Merge pull request #4280 from rust-lang/fixes-counting-line-simplify

Ferris: always show, even when it’s small
This commit is contained in:
Chris Krycho
2025-03-17 11:50:24 -06:00
committed by GitHub
2 changed files with 26 additions and 2 deletions
+22
View File
@@ -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;
}
+4 -2
View File
@@ -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) {