Skip to content

Commit c7e7de4

Browse files
Rollup merge of #85118 - GuillaumeGomez:clipboard-svg, r=Nemo157
Use an SVG image for clipboard instead of unicode character Linked to rust-lang/docs.rs#1394. cc `@jsha` r? `@Nemo157`
2 parents 205a0d3 + 7450f70 commit c7e7de4

File tree

9 files changed

+49
-11
lines changed

9 files changed

+49
-11
lines changed

src/librustdoc/html/layout.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ crate struct Page<'a> {
3434
crate static_extra_scripts: &'a [&'a str],
3535
}
3636

37+
impl<'a> Page<'a> {
38+
crate fn get_static_root_path(&self) -> &str {
39+
self.static_root_path.unwrap_or(self.root_path)
40+
}
41+
}
42+
3743
crate fn render<T: Print, S: Print>(
3844
layout: &Layout,
3945
page: &Page<'_>,
4046
sidebar: S,
4147
t: T,
4248
style_files: &[StylePath],
4349
) -> String {
44-
let static_root_path = page.static_root_path.unwrap_or(page.root_path);
50+
let static_root_path = page.get_static_root_path();
4551
format!(
4652
"<!DOCTYPE html>\
4753
<html lang=\"en\">\

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'tcx> Context<'tcx> {
215215
&self.shared.layout,
216216
&page,
217217
|buf: &mut _| print_sidebar(self, it, buf),
218-
|buf: &mut _| print_item(self, it, buf),
218+
|buf: &mut _| print_item(self, it, buf, &page),
219219
&self.shared.style_files,
220220
)
221221
} else {

src/librustdoc/html/render/print_item.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ use crate::formats::{AssocItemRender, Impl, RenderMode};
2222
use crate::html::escape::Escape;
2323
use crate::html::format::{print_abi_with_space, print_where_clause, Buffer, PrintWithSpace};
2424
use crate::html::highlight;
25+
use crate::html::layout::Page;
2526
use crate::html::markdown::MarkdownSummaryLine;
2627

27-
pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
28+
pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, page: &Page<'_>) {
2829
debug_assert!(!item.is_stripped());
2930
// Write the breadcrumb trail header for the top
3031
buf.write_str("<h1 class=\"fqn\"><span class=\"in-band\">");
@@ -74,7 +75,16 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer)
7475
}
7576
}
7677
write!(buf, "<a class=\"{}\" href=\"\">{}</a>", item.type_(), item.name.as_ref().unwrap());
77-
write!(buf, "<button id=\"copy-path\" onclick=\"copy_path(this)\">⎘</button>");
78+
write!(
79+
buf,
80+
"<button id=\"copy-path\" onclick=\"copy_path(this)\">\
81+
<img src=\"{static_root_path}clipboard{suffix}.svg\" \
82+
width=\"19\" height=\"18\" \
83+
alt=\"Copy item import\">\
84+
</button>",
85+
static_root_path = page.get_static_root_path(),
86+
suffix = page.resource_suffix,
87+
);
7888

7989
buf.write_str("</span>"); // in-band
8090
buf.write_str("<span class=\"out-of-band\">");

src/librustdoc/html/render/write_shared.rs

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub(super) fn write_shared(
207207
}
208208
write_toolchain("brush.svg", static_files::BRUSH_SVG)?;
209209
write_toolchain("wheel.svg", static_files::WHEEL_SVG)?;
210+
write_toolchain("clipboard.svg", static_files::CLIPBOARD_SVG)?;
210211
write_toolchain("down-arrow.svg", static_files::DOWN_ARROW_SVG)?;
211212

212213
let mut themes: Vec<&String> = themes.iter().collect();
+1
Loading

src/librustdoc/html/static/main.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1252,15 +1252,31 @@ function hideThemeButtonState() {
12521252
document.execCommand('copy');
12531253
document.body.removeChild(el);
12541254

1255-
but.textContent = '✓';
1255+
// There is always one children, but multiple childNodes.
1256+
but.children[0].style.display = 'none';
1257+
1258+
var tmp;
1259+
if (but.childNodes.length < 2) {
1260+
tmp = document.createTextNode('✓');
1261+
but.appendChild(tmp);
1262+
} else {
1263+
onEachLazy(but.childNodes, function(e) {
1264+
if (e.nodeType === Node.TEXT_NODE) {
1265+
tmp = e;
1266+
return true;
1267+
}
1268+
});
1269+
tmp.textContent = '✓';
1270+
}
12561271

12571272
if (reset_button_timeout !== null) {
12581273
window.clearTimeout(reset_button_timeout);
12591274
}
12601275

12611276
function reset_button() {
1262-
but.textContent = '';
1277+
tmp.textContent = '';
12631278
reset_button_timeout = null;
1279+
but.children[0].style.display = "";
12641280
}
12651281

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

src/librustdoc/html/static/rustdoc.css

+5-4
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,12 @@ h4 > .notable-traits {
13211321
}
13221322

13231323
#copy-path {
1324-
height: 30px;
1325-
font-size: 18px;
13261324
margin-left: 10px;
1327-
padding: 0 6px;
1328-
width: 28px;
1325+
padding: 0;
1326+
padding-left: 2px;
1327+
}
1328+
#copy-path> img {
1329+
margin-bottom: 2px;
13291330
}
13301331

13311332
#theme-choices {

src/librustdoc/html/static/themes/ayu.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ kbd {
509509
color: #fff;
510510
}
511511

512-
#theme-picker > img, #settings-menu > img {
512+
#theme-picker > img, #settings-menu > img, #copy-path > img {
513513
filter: invert(100);
514514
}
515515

src/librustdoc/html/static_files.rs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ crate static BRUSH_SVG: &[u8] = include_bytes!("static/brush.svg");
4141
/// The file contents of `wheel.svg`, the icon used for the settings button.
4242
crate static WHEEL_SVG: &[u8] = include_bytes!("static/wheel.svg");
4343

44+
/// The file contents of `clipboard.svg`, the icon used for the "copy path" button.
45+
crate static CLIPBOARD_SVG: &[u8] = include_bytes!("static/clipboard.svg");
46+
4447
/// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox.
4548
crate static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/down-arrow.svg");
4649

0 commit comments

Comments
 (0)