From 9847e793509046ad5aebd95cc0ec96c2f3000067 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 17 Mar 2025 10:54:10 -0600 Subject: [PATCH 1/2] Ferris: simplify line counting for size determination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a trivial thing, but I found the previous “replace a terminal newline and then count the rest” rather less than obvious. Make the logic more explicit and, as a fun bonus, skip allocating an extra string along the way. (Not that it matters, in this case, but it’s always nice to make that kind of improvement.) --- ferris.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) { From 8372e56d40fd876b07e539c04bf669e784b1e272 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Mon, 17 Mar 2025 10:54:10 -0600 Subject: [PATCH 2/2] Ferris: always show Ferrises, even if small MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, when we incorporated Ferris into the container for the buttons, we were bringing along the visibility of the buttons even when it was important to know that the code wouldn’t compile. This changes that by showing and hiding the buttons themselves rather than their container. Fixes #4274 --- ferris.css | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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; +}