Skip to content

Commit af664be

Browse files
committed
rustdoc: include link on all.html location header
This avoids a subtle layout shift when switching from the crate page to all items.
1 parent 13471d3 commit af664be

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/librustdoc/html/render/context.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
600600
};
601601
let all = shared.all.replace(AllTypes::new());
602602
let mut sidebar = Buffer::html();
603-
if shared.cache.crate_version.is_some() {
604-
write!(sidebar, "<h2 class=\"location\">Crate {}</h2>", crate_name)
605-
};
603+
write!(sidebar, "<h2 class=\"location\"><a href=\"#\">Crate {}</a></h2>", crate_name);
606604

607605
let mut items = Buffer::html();
608606
sidebar_module_like(&mut items, all.item_sections());

tests/rustdoc-gui/sidebar.goml

+14
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,17 @@ assert-property: (".sidebar", {"clientWidth": "200"})
149149
click: "#toggle-all-docs"
150150
assert-text: ("#toggle-all-docs", "[−]")
151151
assert-property: (".sidebar", {"clientWidth": "200"})
152+
153+
// Checks that all.html and index.html have their sidebar link in the same place.
154+
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
155+
store-property: (index_sidebar_width, ".sidebar .location a", "clientWidth")
156+
store-property: (index_sidebar_height, ".sidebar .location a", "clientHeight")
157+
store-property: (index_sidebar_x, ".sidebar .location a", "offsetTop")
158+
store-property: (index_sidebar_y, ".sidebar .location a", "offsetLeft")
159+
goto: "file://" + |DOC_PATH| + "/test_docs/all.html"
160+
assert-property: (".sidebar .location a", {
161+
"clientWidth": |index_sidebar_width|,
162+
"clientHeight": |index_sidebar_height|,
163+
"offsetTop": |index_sidebar_x|,
164+
"offsetLeft": |index_sidebar_y|,
165+
})

0 commit comments

Comments
 (0)