Skip to content

Commit 6c91ce2

Browse files
authored
Rollup merge of #108686 - notriddle:notriddle/jank-all, r=jsha
rustdoc: include link on all.html location header This avoids a subtle layout shift when switching from the crate page to all items. ## Before | index.html | all.html | |------------|----------| | ![image](https://user-images.githubusercontent.com/1593513/222607866-4eac3f55-314c-4273-9664-503f2a79ad0a.png) | ![image](https://user-images.githubusercontent.com/1593513/222607895-2d6bac3b-f66a-47d4-b234-360f6f8e1ee3.png) | ## After | index.html | all.html | |------------|----------| | ![image](https://user-images.githubusercontent.com/1593513/222607866-4eac3f55-314c-4273-9664-503f2a79ad0a.png) | ![image](https://user-images.githubusercontent.com/1593513/222607997-e72c48a0-02c7-42a7-80c2-cd6bed48bd15.png) |
2 parents 7c306f6 + af664be commit 6c91ce2

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)