Skip to content

Commit 869b7bc

Browse files
authored
Rollup merge of #92795 - jsha:link-to-top, r=GuillaumeGomez
Link sidebar "location" heading to top of page This makes it easy, when you are scrolled far down in a page, to jump back to the top. Demo: https://rustdoc.crud.net/jsha/link-to-top/std/string/struct.String.html r? ``@GuillaumeGomez``
2 parents 1fbd6ae + 7781636 commit 869b7bc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
17361736
{
17371737
write!(
17381738
buffer,
1739-
"<h2 class=\"location\">{}{}</h2>",
1739+
"<h2 class=\"location\"><a href=\"#\">{}{}</a></h2>",
17401740
match *it.kind {
17411741
clean::StructItem(..) => "Struct ",
17421742
clean::TraitItem(..) => "Trait ",

src/test/rustdoc-gui/sidebar.goml

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ click: "#structs + .item-table .item-left > a"
2222
assert-count: (".sidebar .location", 2)
2323
// We check that there is no crate listed outside of the top level.
2424
assert-false: ".sidebar-elems > .crate"
25+
26+
click: ".sidebar-links a"
27+
assert-property: ("html", {"scrollTop": "389"})
28+
29+
click: ".sidebar h2.location"
30+
assert-property: ("html", {"scrollTop": "0"})
31+
2532
// We now go back to the crate page to click on the "lib2" crate link.
2633
goto: file://|DOC_PATH|/test_docs/index.html
2734
click: ".sidebar-elems .crate > ul > li:first-child > a"

0 commit comments

Comments
 (0)