about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-03-21 10:38:24 -0700
committerMichael Howell <michael@notriddle.com>2023-09-21 15:16:44 -0700
commit20b93b951aaa75bd32ec1c1c63eac5dbccc35156 (patch)
tree5c22422dc0f065d4216b2aef97fe2098c36dbba2
parent3583e86674749c279e7edd96641255bbf8595de1 (diff)
downloadrust-20b93b951aaa75bd32ec1c1c63eac5dbccc35156.tar.gz
rust-20b93b951aaa75bd32ec1c1c63eac5dbccc35156.zip
rustdoc: wait for section to open before trying to highlight
This fixes a problem where hash rewriting doesn't work with
`:target` CSS rules.
-rw-r--r--src/librustdoc/html/static/js/main.js8
-rw-r--r--tests/rustdoc-gui/search-result-impl-disambiguation.goml2
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"