about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/main.js
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2024-09-29 15:15:29 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2024-09-29 19:43:09 +0000
commit5726000b2de7052915e808e42a75d6b60b3db540 (patch)
tree94b514d96514586268977832816e75e1402d261d /src/librustdoc/html/static/js/main.js
parent2da3cb9cab706ff029ee5a40c6dee1c1f188e0bb (diff)
downloadrust-5726000b2de7052915e808e42a75d6b60b3db540.tar.gz
rust-5726000b2de7052915e808e42a75d6b60b3db540.zip
Copy correct path to clipboard for modules/keywords/primitives
Diffstat (limited to 'src/librustdoc/html/static/js/main.js')
-rw-r--r--src/librustdoc/html/static/js/main.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 0d556e0a682..984b0877d8d 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -1828,11 +1828,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
         return;
     }
     but.onclick = () => {
-        const path = [];
-        onEachLazy(document.querySelectorAll(".rustdoc-breadcrumbs a"), a => {
-            path.push(a.textContent);
-        });
-        path.push(document.querySelector("title").textContent.split(" ")[0]);
+        // Most page titles are '<Item> in <path::to::module> - Rust', except
+        // modules (which don't have the first part) and keywords/primitives
+        // (which don't have a module path)
+        const title = document.querySelector("title").textContent.replace(" - Rust", "");
+        const [item, module] = title.split(" in ");
+        const path = [item];
+        if (module !== undefined) {
+            path.unshift(module);
+        }
 
         copyContentToClipboard(path.join("::"));
         copyButtonAnimation(but);