From ec754cf2012d1aecf7fca8fa66c846d79e7b94a4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 16 Apr 2024 23:55:32 +0200 Subject: [PATCH 1/2] Fix copy-path button --- src/librustdoc/html/static/css/rustdoc.css | 17 ++++++++++------- src/librustdoc/html/static/js/main.js | 20 ++------------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e9c687b42fadc..74c9130fd77bd 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1627,24 +1627,27 @@ a.tooltip:hover::after { color: var(--copy-path-button-color); background: var(--main-background-color); height: 34px; + width: 33px; margin-left: 10px; padding: 0; padding-left: 2px; border: 0; - width: 33px; - line-height: 0; font-size: 0; } - -#copy-path:before { +#copy-path::before { filter: var(--copy-path-img-filter); content: url('clipboard-24048e6d87f63d07.svg'); - width: 19px; - height: 18px; } -#copy-path:hover:before { +#copy-path:hover::before { filter: var(--copy-path-img-hover-filter); } +#copy-path.clicked::before { + /* Checkmark */ + content: url('data:image/svg+xml,\ + \ + '); +} @keyframes rotating { from { diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 940b62be0c94d..2c114b1cf553f 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1797,31 +1797,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm document.execCommand("copy"); document.body.removeChild(el); - // There is always one children, but multiple childNodes. - but.children[0].style.display = "none"; - - let tmp; - if (but.childNodes.length < 2) { - tmp = document.createTextNode("✓"); - but.appendChild(tmp); - } else { - onEachLazy(but.childNodes, e => { - if (e.nodeType === Node.TEXT_NODE) { - tmp = e; - return true; - } - }); - tmp.textContent = "✓"; - } + but.classList.add("clicked"); if (reset_button_timeout !== null) { window.clearTimeout(reset_button_timeout); } function reset_button() { - tmp.textContent = ""; reset_button_timeout = null; - but.children[0].style.display = ""; + but.classList.remove("clicked"); } reset_button_timeout = window.setTimeout(reset_button, 1000); From 1ebc9efa786c3312b5c8b5659aeffc048ccd6f3b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 17 Apr 2024 00:02:39 +0200 Subject: [PATCH 2/2] Add GUI test for copy path button --- tests/rustdoc-gui/copy-path.goml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/rustdoc-gui/copy-path.goml diff --git a/tests/rustdoc-gui/copy-path.goml b/tests/rustdoc-gui/copy-path.goml new file mode 100644 index 0000000000000..dc05b96f7aed1 --- /dev/null +++ b/tests/rustdoc-gui/copy-path.goml @@ -0,0 +1,15 @@ +// Checks that the "copy path" button is not triggering JS error and its display +// isn't broken. +go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" + +// First we store the size of the button before we click on it. +store-size: ("#copy-path", {"width": width, "height": height}) +click: "#copy-path" +// We wait for the new text to appear. +wait-for: "#copy-path.clicked" +// We check that the size didn't change. +assert-size: ("#copy-path.clicked", {"width": |width|, "height": |height|}) +// We wait for the button to turn back to its original state. +wait-for: "#copy-path:not(.clicked)" +// We check that the size is still the same. +assert-size: ("#copy-path:not(.clicked)", {"width": |width|, "height": |height|})