Skip to content

Commit c0d0168

Browse files
Fix copy-path button
1 parent ad18fe0 commit c0d0168

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,23 +1626,25 @@ a.tooltip:hover::after {
16261626
#copy-path {
16271627
color: var(--copy-path-button-color);
16281628
background: var(--main-background-color);
1629-
height: 34px;
1629+
height: 30px;
1630+
width: 33px;
16301631
margin-left: 10px;
16311632
padding: 0;
16321633
padding-left: 2px;
16331634
border: 0;
1634-
width: 33px;
1635-
line-height: 0;
1635+
overflow: hidden;
16361636
font-size: 0;
1637+
display: inline-block;
1638+
vertical-align: bottom;
16371639
}
1638-
1639-
#copy-path:before {
1640+
#copy-path.clicked {
1641+
font-size: 26px;
1642+
}
1643+
#copy-path:not(.clicked)::before {
16401644
filter: var(--copy-path-img-filter);
16411645
content: url('clipboard-24048e6d87f63d07.svg');
1642-
width: 19px;
1643-
height: 18px;
16441646
}
1645-
#copy-path:hover:before {
1647+
#copy-path:not(.clicked):hover::before {
16461648
filter: var(--copy-path-img-hover-filter);
16471649
}
16481650

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,8 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
17751775
if (!but) {
17761776
return;
17771777
}
1778+
let butTextNode = null;
1779+
17781780
but.onclick = () => {
17791781
const parent = but.parentElement;
17801782
const path = [];
@@ -1797,31 +1799,22 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
17971799
document.execCommand("copy");
17981800
document.body.removeChild(el);
17991801

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

1807+
butTextNode.textContent = "✓";
1808+
but.classList.add("clicked");
1809+
18171810
if (reset_button_timeout !== null) {
18181811
window.clearTimeout(reset_button_timeout);
18191812
}
18201813

18211814
function reset_button() {
1822-
tmp.textContent = "";
1815+
butTextNode.textContent = "";
18231816
reset_button_timeout = null;
1824-
but.children[0].style.display = "";
1817+
but.classList.remove("clicked");
18251818
}
18261819

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

0 commit comments

Comments
 (0)