Skip to content

Commit 5726000

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

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • src/librustdoc/html/static/js

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

Lines changed: 9 additions & 5 deletions
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-
constpath=[];
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+
consttitle=document.querySelector("title").textContent.replace(" - Rust","");
1835+
const[item,module]=title.split(" in ");
1836+
constpath=[item];
1837+
if(module!==undefined){
1838+
path.unshift(module);
1839+
}
18361840

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

0 commit comments

Comments
 (0)