about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-07-30 20:58:09 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-08-05 11:05:40 +0200
commit59cb15946df94502bd6aa240e8c3700a4326a433 (patch)
tree2a4e80f4cee843cea1824f7b72599e2c662237aa
parente2da2fb387c0874fbe06e4cb75f3dd5e6ef7bdc2 (diff)
downloadrust-59cb15946df94502bd6aa240e8c3700a4326a433.tar.gz
rust-59cb15946df94502bd6aa240e8c3700a4326a433.zip
Prevent clicking on a link or on a button to toggle the code example buttons visibility
-rw-r--r--src/librustdoc/html/static/js/main.js8
-rw-r--r--tests/rustdoc-gui/code-example-buttons.goml6
2 files changed, 12 insertions, 2 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 67731f35496..a225faa87f4 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -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;
     }
diff --git a/tests/rustdoc-gui/code-example-buttons.goml b/tests/rustdoc-gui/code-example-buttons.goml
index a8505812b88..4f037ec79f5 100644
--- a/tests/rustdoc-gui/code-example-buttons.goml
+++ b/tests/rustdoc-gui/code-example-buttons.goml
@@ -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],