Skip to content

Commit

Permalink
Rollup merge of #131023 - clubby789:doc-item-path, r=notriddle
Browse files Browse the repository at this point in the history
Copy correct path to clipboard for modules/keywords/primitives

Fixes #131021
  • Loading branch information
matthiaskrgr authored Sep 30, 2024
2 parents c3ce4e6 + 5726000 commit b6b43af
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b6b43af

Please sign in to comment.