Skip to content

Commit 5a85632

Browse files
Correctly handle code examples buttons position
1 parent 4825fb1 commit 5a85632

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
3434
</g></svg>');
3535
--button-left-margin: 4px;
3636
--button-border-radius: 2px;
37+
--pre-line-height: 1.5rem;
3738
}
3839

3940
/* See FiraSans-LICENSE.txt for the Fira Sans license. */
@@ -365,7 +366,7 @@ code, pre, .code-header {
365366
}
366367
pre {
367368
padding: 14px;
368-
line-height: 1.5; /* https://github.com/rust-lang/rust/issues/105906 */
369+
line-height: var(--pre-line-height); /* https://github.com/rust-lang/rust/issues/105906 */
369370
}
370371
pre.item-decl {
371372
overflow-x: auto;
@@ -2278,6 +2279,9 @@ in src-script.js and main.js
22782279
/* Dirty hacky to force it to remain on the same line as the line numbers. */
22792280
width: 10px;
22802281
}
2282+
.example-wrap.scraped-example .button-holder {
2283+
top: calc(var(--pre-line-height) + 4px);
2284+
}
22812285
}
22822286

22832287
/* Should have min-width: (N + 1)px where N is the mobile breakpoint above. */

tests/rustdoc-gui/code-example-buttons.goml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,24 @@ call-function: ("check-buttons",{
9494
"filter": "invert(0.5)",
9595
"filter_hover": "invert(0.35)",
9696
})
97+
98+
define-function: (
99+
"check-buttons-position",
100+
[pre_selector],
101+
block {
102+
move-cursor-to: |pre_selector| + " .rust:not(.item-decl)"
103+
store-position: (|pre_selector| + " .rust:not(.item-decl)", {"x": x, "y": y})
104+
assert-position: (|pre_selector| + " .rust:not(.item-decl) + .button-holder", {
105+
"y": |y| + 4,
106+
})
107+
}
108+
)
109+
110+
call-function: ("check-buttons-position", {"pre_selector": ".example-wrap"})
111+
112+
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
113+
// We should work as well for scraped examples.
114+
call-function: ("check-buttons-position", {"pre_selector": ".example-wrap.scraped-example"})
115+
// And also when the scraped example "title" goes above.
116+
set-window-size: (600, 600)
117+
call-function: ("check-buttons-position", {"pre_selector": ".example-wrap.scraped-example"})

0 commit comments

Comments
 (0)