Skip to content

Commit 8087ac6

Browse files
authored
Unrolled build for rust-lang#127932
Rollup merge of rust-lang#127932 - notriddle:notriddle/current, r=GuillaumeGomez rustdoc: fix `current` class on sidebar modnav | Before | After | | -- | -- | | ![image](https://github.com/user-attachments/assets/35866be8-5a58-41eb-9169-b2bb403fe7cd) | ![image](https://github.com/user-attachments/assets/89b087ea-82bf-49f5-9c87-20162880eb32)
2 parents 11e5724 + 0c932b7 commit 8087ac6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/librustdoc/html/static/js/main.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,13 @@ function preLoadCss(cssUrl) {
529529
}
530530
const link = document.createElement("a");
531531
link.href = path;
532-
if (path === current_page) {
533-
link.className = "current";
534-
}
535532
link.textContent = name;
536533
const li = document.createElement("li");
534+
// Don't "optimize" this to just use `path`.
535+
// We want the browser to normalize this into an absolute URL.
536+
if (link.href === current_page) {
537+
li.classList.add("current");
538+
}
537539
li.appendChild(link);
538540
ul.appendChild(li);
539541
}

tests/rustdoc-gui/sidebar.goml

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ click: "#structs + .item-table .item-name > a"
7272
assert-count: (".sidebar .sidebar-crate", 1)
7373
assert-count: (".sidebar .location", 1)
7474
assert-count: (".sidebar h2", 3)
75+
assert-text: (".sidebar-elems ul.block > li.current > a", "Foo")
7576
// We check that there is no crate listed outside of the top level.
7677
assert-false: ".sidebar-elems > .crate"
7778

@@ -110,6 +111,7 @@ click: "#functions + .item-table .item-name > a"
110111
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
111112
assert-count: (".sidebar .location", 0)
112113
assert-count: (".sidebar h2", 1)
114+
assert-text: (".sidebar-elems ul.block > li.current > a", "foobar")
113115
// We check that we don't have the crate list.
114116
assert-false: ".sidebar-elems > .crate"
115117

@@ -118,6 +120,7 @@ assert-property: (".sidebar", {"clientWidth": "200"})
118120
assert-text: (".sidebar > .sidebar-crate > h2 > a", "lib2")
119121
assert-text: (".sidebar > .location", "Module module")
120122
assert-count: (".sidebar .location", 1)
123+
assert-text: (".sidebar-elems ul.block > li.current > a", "module")
121124
// Module page requires three headings:
122125
// - Presistent crate branding (name and version)
123126
// - Module name, followed by TOC for module headings
@@ -138,6 +141,7 @@ assert-text: (".sidebar > .sidebar-elems > h2", "In lib2::module::sub_module")
138141
assert-property: (".sidebar > .sidebar-elems > h2 > a", {
139142
"href": "/module/sub_module/index.html",
140143
}, ENDS_WITH)
144+
assert-text: (".sidebar-elems ul.block > li.current > a", "sub_sub_module")
141145
// We check that we don't have the crate list.
142146
assert-false: ".sidebar-elems .crate"
143147
assert-text: (".sidebar-elems > section ul > li:nth-child(1)", "Functions")

0 commit comments

Comments
 (0)