Skip to content

Commit

Permalink
rustdoc: include link on all.html location header
Browse files Browse the repository at this point in the history
This avoids a subtle layout shift when switching from the crate page
to all items.
  • Loading branch information
notriddle committed Mar 4, 2023
1 parent 13471d3 commit af664be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
};
let all = shared.all.replace(AllTypes::new());
let mut sidebar = Buffer::html();
if shared.cache.crate_version.is_some() {
write!(sidebar, "<h2 class=\"location\">Crate {}</h2>", crate_name)
};
write!(sidebar, "<h2 class=\"location\"><a href=\"#\">Crate {}</a></h2>", crate_name);

let mut items = Buffer::html();
sidebar_module_like(&mut items, all.item_sections());
Expand Down
14 changes: 14 additions & 0 deletions tests/rustdoc-gui/sidebar.goml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,17 @@ assert-property: (".sidebar", {"clientWidth": "200"})
click: "#toggle-all-docs"
assert-text: ("#toggle-all-docs", "[−]")
assert-property: (".sidebar", {"clientWidth": "200"})

// Checks that all.html and index.html have their sidebar link in the same place.
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
store-property: (index_sidebar_width, ".sidebar .location a", "clientWidth")
store-property: (index_sidebar_height, ".sidebar .location a", "clientHeight")
store-property: (index_sidebar_x, ".sidebar .location a", "offsetTop")
store-property: (index_sidebar_y, ".sidebar .location a", "offsetLeft")
goto: "file://" + |DOC_PATH| + "/test_docs/all.html"
assert-property: (".sidebar .location a", {
"clientWidth": |index_sidebar_width|,
"clientHeight": |index_sidebar_height|,
"offsetTop": |index_sidebar_x|,
"offsetLeft": |index_sidebar_y|,
})

0 comments on commit af664be

Please sign in to comment.