Skip to content

Commit 20b93b9

Browse files
committed
rustdoc: wait for section to open before trying to highlight
This fixes a problem where hash rewriting doesn't work with `:target` CSS rules.
1 parent 3583e86 commit 20b93b9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,12 @@ function preLoadCss(cssUrl) {
370370
item => {
371371
const numbered = /([^-]+)-([0-9]+)/.exec(item.id);
372372
if (item.id === assocId || (numbered && numbered[1] === assocId)) {
373-
expandSection(item.id);
374-
window.location = "#" + item.id;
373+
openParentDetails(item);
374+
item.scrollIntoView();
375+
// Let the section expand itself before trying to highlight
376+
setTimeout(() => {
377+
window.location.replace("#" + item.id);
378+
}, 0);
375379
}
376380
}
377381
);

tests/rustdoc-gui/search-result-impl-disambiguation.goml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ wait-for: "#impl-ZyxwvutMethodDisambiguation"
2020
assert-document-property: ({
2121
"URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation"
2222
}, ENDS_WITH)
23+
assert: "section:target"
2324

2425
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
2526

@@ -39,3 +40,4 @@ wait-for: "#impl-ZyxwvutMethodDisambiguation"
3940
assert-document-property: ({
4041
"URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation-1"
4142
}, ENDS_WITH)
43+
assert: "section:target"

0 commit comments

Comments
 (0)