about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-03-30 14:06:37 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2020-07-02 13:19:04 +0200
commitfc61cca41cb81af3c8167e8ceb596e2077d70310 (patch)
tree1acf9264909cc25217ea5d6a4951e8e353c6cc9f
parent0fcb7dabac1409f4ff51867aa5e9e0e51ec6e248 (diff)
downloadrust-fc61cca41cb81af3c8167e8ceb596e2077d70310.tar.gz
rust-fc61cca41cb81af3c8167e8ceb596e2077d70310.zip
Expand sub code blocks block content when hidden when the page hash refers to it
-rw-r--r--src/librustdoc/html/static/main.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 93929a67d49..8839d4fc4e5 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -306,6 +306,14 @@ function defocusSearchBar() {
     function expandSection(id) {
         var elem = document.getElementById(id);
         if (elem && isHidden(elem)) {
+            if (elem.tagName === "CODE" && elem.parentNode.tagName === "H4") {
+                // We are in a trait implementation, what we want is the parent.
+                elem = elem.parentNode;
+                if (elem.id !== null && elem.id.length > 0) {
+                    // Change the id to the parent which is "more clear" and better for users.
+                    window.location.hash = elem.id;
+                }
+            }
             var h3 = elem.parentNode.previousElementSibling;
             if (h3 && h3.tagName !== "H3") {
                 h3 = h3.previousElementSibling; // skip div.docblock