mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Tweak how the "copy path" rustdoc button works to allow some accessibility tool to work with rustdoc
This commit is contained in:
@@ -2123,20 +2123,27 @@ function preLoadCss(cssUrl) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
but.onclick = () => {
|
but.onclick = () => {
|
||||||
// Most page titles are '<Item> in <path::to::module> - Rust', except
|
// We get the path from the "breadcrumbs" and the actual item name.
|
||||||
// modules (which don't have the first part) and keywords/primitives
|
let path = "";
|
||||||
// (which don't have a module path)
|
// @ts-expect-error
|
||||||
const titleElement = document.querySelector("title");
|
const heading = document.getElementById(MAIN_ID).querySelector(".main-heading");
|
||||||
const title = titleElement && titleElement.textContent ?
|
|
||||||
titleElement.textContent.replace(" - Rust", "") : "";
|
|
||||||
const [item, module] = title.split(" in ");
|
|
||||||
const path = [item];
|
|
||||||
if (module !== undefined) {
|
|
||||||
path.unshift(module);
|
|
||||||
}
|
|
||||||
|
|
||||||
copyContentToClipboard(path.join("::"));
|
if (heading) {
|
||||||
copyButtonAnimation(but);
|
const breadcrumbs = heading.querySelector(".rustdoc-breadcrumbs");
|
||||||
|
if (breadcrumbs) {
|
||||||
|
// @ts-expect-error
|
||||||
|
path = breadcrumbs.innerText;
|
||||||
|
if (path.length > 0) {
|
||||||
|
path += "::";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
path += heading.querySelector("h1 > span").innerText;
|
||||||
|
|
||||||
|
copyContentToClipboard(path);
|
||||||
|
copyButtonAnimation(but);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,3 +18,19 @@ assert-size: ("#copy-path.clicked", {"width": |width|, "height": |height|})
|
|||||||
wait-for: "#copy-path:not(.clicked)"
|
wait-for: "#copy-path:not(.clicked)"
|
||||||
// We check that the size is still the same.
|
// We check that the size is still the same.
|
||||||
assert-size: ("#copy-path:not(.clicked)", {"width": |width|, "height": |height|})
|
assert-size: ("#copy-path:not(.clicked)", {"width": |width|, "height": |height|})
|
||||||
|
|
||||||
|
// Check the path for a module.
|
||||||
|
go-to: "file://" + |DOC_PATH| + "/test_docs/foreign_impl_order/index.html"
|
||||||
|
click: "#copy-path"
|
||||||
|
// We wait for the new text to appear.
|
||||||
|
wait-for: "#copy-path.clicked"
|
||||||
|
// We check that the clipboard value is the expected one.
|
||||||
|
assert-clipboard: "test_docs::foreign_impl_order"
|
||||||
|
|
||||||
|
// Check the path for the crate.
|
||||||
|
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
|
||||||
|
click: "#copy-path"
|
||||||
|
// We wait for the new text to appear.
|
||||||
|
wait-for: "#copy-path.clicked"
|
||||||
|
// We check that the clipboard value is the expected one.
|
||||||
|
assert-clipboard: "test_docs"
|
||||||
|
|||||||
Reference in New Issue
Block a user