about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>2022-01-11 14:39:51 -0800
committerJacob Hoffman-Andrews <github@hoffman-andrews.com>2022-01-14 10:41:30 -0800
commit7781636fc7bd2edc6bf314dc15eb8e9d5cb60ce6 (patch)
treeb80cb6641ad641657d3b80944604409b051eb43c
parent256721ee519f6ff15dc5c1cfaf3ebf9af75efa4a (diff)
downloadrust-7781636fc7bd2edc6bf314dc15eb8e9d5cb60ce6.tar.gz
rust-7781636fc7bd2edc6bf314dc15eb8e9d5cb60ce6.zip
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.
-rw-r--r--src/librustdoc/html/render/mod.rs2
-rw-r--r--src/test/rustdoc-gui/sidebar.goml7
2 files changed, 8 insertions, 1 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index dda74904931..0fdf67124c1 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -1737,7 +1737,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
     {
         write!(
             buffer,
-            "<h2 class=\"location\">{}{}</h2>",
+            "<h2 class=\"location\"><a href=\"#\">{}{}</a></h2>",
             match *it.kind {
                 clean::StructItem(..) => "Struct ",
                 clean::TraitItem(..) => "Trait ",
diff --git a/src/test/rustdoc-gui/sidebar.goml b/src/test/rustdoc-gui/sidebar.goml
index f9c707f81e7..9289244f6f8 100644
--- a/src/test/rustdoc-gui/sidebar.goml
+++ b/src/test/rustdoc-gui/sidebar.goml
@@ -22,6 +22,13 @@ click: "#structs + .item-table .item-left > a"
 assert-count: (".sidebar .location", 2)
 // We check that there is no crate listed outside of the top level.
 assert-false: ".sidebar-elems > .crate"
+
+click: ".sidebar-links a"
+assert-property: ("html", {"scrollTop": "389"})
+
+click: ".sidebar h2.location"
+assert-property: ("html", {"scrollTop": "0"})
+
 // We now go back to the crate page to click on the "lib2" crate link.
 goto: file://|DOC_PATH|/test_docs/index.html
 click: ".sidebar-elems .crate > ul > li:first-child > a"