diff --git a/ferris.css b/ferris.css index fb4a553ffb..513efa1431 100644 --- a/ferris.css +++ b/ferris.css @@ -43,3 +43,25 @@ body.ayu .not_desired_behavior { .ferris-explain { width: 100px; } + +/* + A bit of a hack to make small Ferris use the existing buttons container but + only show/hide the buttons on hover over the `pre`. Targeting `.listing` + increases the specificity of this rule. +*/ +pre > .buttons { + visibility: visible; + opacity: 1; + transition: none; +} + +pre > .buttons button { + visibility: hidden; + opacity: 0; + transition: visibility 0.1s linear, opacity 0.1s linear; +} + +pre:hover > .buttons button { + visibility: visible; + opacity: 1; +} diff --git a/ferris.js b/ferris.js index 08f3292816..13b1ceb9a5 100644 --- a/ferris.js +++ b/ferris.js @@ -40,10 +40,12 @@ function attachFerrises(type) { continue; } - let lines = codeBlock.innerText.replace(/\n$/, "").split(/\n/).length; + let codeLines = codeBlock.innerText; + let extra = codeLines.endsWith("\n") ? 1 : 0; + let numLines = codeLines.split("\n").length - extra; /** @type {'small' | 'large'} */ - let size = lines < 4 ? "small" : "large"; + let size = numLines < 4 ? "small" : "large"; let container = prepareFerrisContainer(codeBlock, size == "small"); if (!container) {