Skip to content

Commit 7781636

Browse files
committed
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.
1 parent 256721e commit 7781636

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
@@ -1737,7 +1737,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
17371737
{
17381738
write!(
17391739
buffer,
1740-
"<h2 class=\"location\">{}{}</h2>",
1740+
"<h2 class=\"location\"><a href=\"#\">{}{}</a></h2>",
17411741
match *it.kind {
17421742
clean::StructItem(..) => "Struct ",
17431743
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)