From 20b93b951aaa75bd32ec1c1c63eac5dbccc35156 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 21 Mar 2023 10:38:24 -0700 Subject: [PATCH] rustdoc: wait for section to open before trying to highlight This fixes a problem where hash rewriting doesn't work with `:target` CSS rules. --- src/librustdoc/html/static/js/main.js | 8 ++++++-- tests/rustdoc-gui/search-result-impl-disambiguation.goml | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 970c2f2d45d..aa8fd7162ee 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -370,8 +370,12 @@ function preLoadCss(cssUrl) { item => { const numbered = /([^-]+)-([0-9]+)/.exec(item.id); if (item.id === assocId || (numbered && numbered[1] === assocId)) { - expandSection(item.id); - window.location = "#" + item.id; + openParentDetails(item); + item.scrollIntoView(); + // Let the section expand itself before trying to highlight + setTimeout(() => { + window.location.replace("#" + item.id); + }, 0); } } ); diff --git a/tests/rustdoc-gui/search-result-impl-disambiguation.goml b/tests/rustdoc-gui/search-result-impl-disambiguation.goml index 98a2cd95773..1596a3c4c6e 100644 --- a/tests/rustdoc-gui/search-result-impl-disambiguation.goml +++ b/tests/rustdoc-gui/search-result-impl-disambiguation.goml @@ -20,6 +20,7 @@ wait-for: "#impl-ZyxwvutMethodDisambiguation" assert-document-property: ({ "URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation" }, ENDS_WITH) +assert: "section:target" goto: "file://" + |DOC_PATH| + "/test_docs/index.html" @@ -39,3 +40,4 @@ wait-for: "#impl-ZyxwvutMethodDisambiguation" assert-document-property: ({ "URL": "struct.ZyxwvutMethodDisambiguation.html#method.method_impl_disambiguation-1" }, ENDS_WITH) +assert: "section:target"