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 Jul 30, 2024
1 parent c5b0a53 commit 27dd6d3
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 @@ -1832,10 +1832,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.tagName === "body" || hasClass(elem, "docblock")) {
if (elem.tagName === "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 27dd6d3

Please sign in to comment.