Skip to content

Commit ac911c4

Browse files
authored
Merge pull request #4280 from rust-lang/fixes-counting-line-simplify
Ferris: always show, even when it’s small
2 parents fb2d874 + 8372e56 commit ac911c4

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

ferris.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,25 @@ body.ayu .not_desired_behavior {
4343
.ferris-explain {
4444
width: 100px;
4545
}
46+
47+
/*
48+
A bit of a hack to make small Ferris use the existing buttons container but
49+
only show/hide the buttons on hover over the `pre`. Targeting `.listing`
50+
increases the specificity of this rule.
51+
*/
52+
pre > .buttons {
53+
visibility: visible;
54+
opacity: 1;
55+
transition: none;
56+
}
57+
58+
pre > .buttons button {
59+
visibility: hidden;
60+
opacity: 0;
61+
transition: visibility 0.1s linear, opacity 0.1s linear;
62+
}
63+
64+
pre:hover > .buttons button {
65+
visibility: visible;
66+
opacity: 1;
67+
}

ferris.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ function attachFerrises(type) {
4040
continue;
4141
}
4242

43-
let lines = codeBlock.innerText.replace(/\n$/, "").split(/\n/).length;
43+
let codeLines = codeBlock.innerText;
44+
let extra = codeLines.endsWith("\n") ? 1 : 0;
45+
let numLines = codeLines.split("\n").length - extra;
4446

4547
/** @type {'small' | 'large'} */
46-
let size = lines < 4 ? "small" : "large";
48+
let size = numLines < 4 ? "small" : "large";
4749

4850
let container = prepareFerrisContainer(codeBlock, size == "small");
4951
if (!container) {

0 commit comments

Comments
 (0)