Skip to content

Commit 56f4ac3

Browse files
authored
Rollup merge of #124041 - GuillaumeGomez:fix-copy-path-button, r=notriddle
Fix copy path button Currently, on all nightly docs, clicking on the "copy path" button triggers a JS error. It's because changes in #123706 forgot to update the JS (it contained an image before but not anymore). I had to make some small changes in the CSS to fix the display when the button was clicked as well. r? ``@notriddle``
2 parents 5260893 + 1ebc9ef commit 56f4ac3

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/librustdoc/html/static/css/rustdoc.css

+10-7
Original file line numberDiff line numberDiff line change
@@ -1627,24 +1627,27 @@ a.tooltip:hover::after {
16271627
color: var(--copy-path-button-color);
16281628
background: var(--main-background-color);
16291629
height: 34px;
1630+
width: 33px;
16301631
margin-left: 10px;
16311632
padding: 0;
16321633
padding-left: 2px;
16331634
border: 0;
1634-
width: 33px;
1635-
line-height: 0;
16361635
font-size: 0;
16371636
}
1638-
1639-
#copy-path:before {
1637+
#copy-path::before {
16401638
filter: var(--copy-path-img-filter);
16411639
content: url('clipboard-24048e6d87f63d07.svg');
1642-
width: 19px;
1643-
height: 18px;
16441640
}
1645-
#copy-path:hover:before {
1641+
#copy-path:hover::before {
16461642
filter: var(--copy-path-img-hover-filter);
16471643
}
1644+
#copy-path.clicked::before {
1645+
/* Checkmark <https://www.svgrepo.com/svg/335033/checkmark> */
1646+
content: url('data:image/svg+xml,<svg viewBox="-1 -1 23 23" xmlns="http://www.w3.org/2000/svg" \
1647+
fill="black" height="18px">\
1648+
<g><path d="M9 19.414l-6.707-6.707 1.414-1.414L9 16.586 20.293 5.293l1.414 1.414"></path>\
1649+
</g></svg>');
1650+
}
16481651

16491652
@keyframes rotating {
16501653
from {

src/librustdoc/html/static/js/main.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -1798,31 +1798,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
17981798
document.execCommand("copy");
17991799
document.body.removeChild(el);
18001800

1801-
// There is always one children, but multiple childNodes.
1802-
but.children[0].style.display = "none";
1803-
1804-
let tmp;
1805-
if (but.childNodes.length < 2) {
1806-
tmp = document.createTextNode("✓");
1807-
but.appendChild(tmp);
1808-
} else {
1809-
onEachLazy(but.childNodes, e => {
1810-
if (e.nodeType === Node.TEXT_NODE) {
1811-
tmp = e;
1812-
return true;
1813-
}
1814-
});
1815-
tmp.textContent = "✓";
1816-
}
1801+
but.classList.add("clicked");
18171802

18181803
if (reset_button_timeout !== null) {
18191804
window.clearTimeout(reset_button_timeout);
18201805
}
18211806

18221807
function reset_button() {
1823-
tmp.textContent = "";
18241808
reset_button_timeout = null;
1825-
but.children[0].style.display = "";
1809+
but.classList.remove("clicked");
18261810
}
18271811

18281812
reset_button_timeout = window.setTimeout(reset_button, 1000);

tests/rustdoc-gui/copy-path.goml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Checks that the "copy path" button is not triggering JS error and its display
2+
// isn't broken.
3+
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
4+
5+
// First we store the size of the button before we click on it.
6+
store-size: ("#copy-path", {"width": width, "height": height})
7+
click: "#copy-path"
8+
// We wait for the new text to appear.
9+
wait-for: "#copy-path.clicked"
10+
// We check that the size didn't change.
11+
assert-size: ("#copy-path.clicked", {"width": |width|, "height": |height|})
12+
// We wait for the button to turn back to its original state.
13+
wait-for: "#copy-path:not(.clicked)"
14+
// We check that the size is still the same.
15+
assert-size: ("#copy-path:not(.clicked)", {"width": |width|, "height": |height|})

0 commit comments

Comments
 (0)