Skip to content

Commit

Permalink
Prevent clicking on a link or on a button to toggle the code example …
Browse files Browse the repository at this point in the history
…buttons visibility
  • Loading branch information
GuillaumeGomez committed Aug 5, 2024
1 parent e2da2fb commit 59cb159
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1829,10 +1829,14 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
function getExampleWrap(event) {
let elem = event.target;
while (!hasClass(elem, "example-wrap")) {
elem = elem.parentElement;
if (elem === document.body || hasClass(elem, "docblock")) {
if (elem === document.body ||
elem.tagName === "A" ||
elem.tagName === "BUTTON" ||
hasClass(elem, "docblock")
) {
return null;
}
elem = elem.parentElement;
}
return elem;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc-gui/code-example-buttons.goml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ move-cursor-to: ".search-input"
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })

// Clicking on the "copy code" button shouldn't make the buttons stick.
click: ".example-wrap .copy-button"
move-cursor-to: ".search-input"
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })

define-function: (
"check-buttons",
[theme, background, filter, filter_hover],
Expand Down

0 comments on commit 59cb159

Please sign in to comment.