Skip to content

Commit bb0fc23

Browse files
committed
Copy correct path to clipboard for modules/keywords/primitives
1 parent 2da3cb9 commit bb0fc23

File tree

1 file changed

+9
-5
lines changed
  • src/librustdoc/html/static/js

1 file changed

+9
-5
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -1828,11 +1828,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
18281828
return;
18291829
}
18301830
but.onclick = () => {
1831-
const path = [];
1832-
onEachLazy(document.querySelectorAll(".rustdoc-breadcrumbs a"), a => {
1833-
path.push(a.textContent);
1834-
});
1835-
path.push(document.querySelector("title").textContent.split(" ")[0]);
1831+
// Most page titles are '<Item> in <path::to::module> - Rust', except
1832+
// modules (which don't have the first part) and keywords/primitives
1833+
// (which don't have a module path)
1834+
const title = document.querySelector("title").textContent.replace(" - Rust", "");
1835+
const [item, module] = title.split(" in ");
1836+
let path = [item];
1837+
if (module !== undefined) {
1838+
path.unshift(module);
1839+
}
18361840

18371841
copyContentToClipboard(path.join("::"));
18381842
copyButtonAnimation(but);

0 commit comments

Comments
 (0)