Skip to content

Commit 59cb159

Browse files
Prevent clicking on a link or on a button to toggle the code example buttons visibility
1 parent e2da2fb commit 59cb159

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1829,10 +1829,14 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
18291829
function getExampleWrap(event) {
18301830
let elem = event.target;
18311831
while (!hasClass(elem, "example-wrap")) {
1832-
elem = elem.parentElement;
1833-
if (elem === document.body || hasClass(elem, "docblock")) {
1832+
if (elem === document.body ||
1833+
elem.tagName === "A" ||
1834+
elem.tagName === "BUTTON" ||
1835+
hasClass(elem, "docblock")
1836+
) {
18341837
return null;
18351838
}
1839+
elem = elem.parentElement;
18361840
}
18371841
return elem;
18381842
}

tests/rustdoc-gui/code-example-buttons.goml

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ move-cursor-to: ".search-input"
2121
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
2222
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })
2323

24+
// Clicking on the "copy code" button shouldn't make the buttons stick.
25+
click: ".example-wrap .copy-button"
26+
move-cursor-to: ".search-input"
27+
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
28+
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })
29+
2430
define-function: (
2531
"check-buttons",
2632
[theme, background, filter, filter_hover],

0 commit comments

Comments
 (0)