Skip to content

Commit 68c2b05

Browse files
Prevent clicking on a link or on a button to toggle the code example buttons visibility
1 parent c5b0a53 commit 68c2b05

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
@@ -1832,10 +1832,14 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
18321832
function getExampleWrap(event) {
18331833
let elem = event.target;
18341834
while (!hasClass(elem, "example-wrap")) {
1835-
elem = elem.parentElement;
1836-
if (elem.tagName === "body" || hasClass(elem, "docblock")) {
1835+
if (elem.tagName === "BODY" ||
1836+
elem.tagName === "A" ||
1837+
elem.tagName === "BUTTON" ||
1838+
hasClass(elem, "docblock"))
1839+
{
18371840
return null;
18381841
}
1842+
elem = elem.parentElement;
18391843
}
18401844
return elem;
18411845
}

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)