Add a button to copy the "use statement"
This commit is contained in:
parent
f35e587db4
commit
828179d687
8 changed files with 58 additions and 14 deletions
|
@ -1354,6 +1354,7 @@ fn init_id_map() -> FxHashMap<String, usize> {
|
||||||
map.insert("default-settings".to_owned(), 1);
|
map.insert("default-settings".to_owned(), 1);
|
||||||
map.insert("rustdoc-vars".to_owned(), 1);
|
map.insert("rustdoc-vars".to_owned(), 1);
|
||||||
map.insert("sidebar-vars".to_owned(), 1);
|
map.insert("sidebar-vars".to_owned(), 1);
|
||||||
|
map.insert("copy-path".to_owned(), 1);
|
||||||
// This is the list of IDs used by rustdoc sections.
|
// This is the list of IDs used by rustdoc sections.
|
||||||
map.insert("fields".to_owned(), 1);
|
map.insert("fields".to_owned(), 1);
|
||||||
map.insert("variants".to_owned(), 1);
|
map.insert("variants".to_owned(), 1);
|
||||||
|
|
|
@ -73,6 +73,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write!(buf, "<a class=\"{}\" href=\"\">{}</a>", item.type_(), item.name.as_ref().unwrap());
|
write!(buf, "<a class=\"{}\" href=\"\">{}</a>", item.type_(), item.name.as_ref().unwrap());
|
||||||
|
write!(buf, "<button id=\"copy-path\" onclick=\"copy_path(this)\">⎘</button>");
|
||||||
|
|
||||||
buf.write_str("</span>"); // in-band
|
buf.write_str("</span>"); // in-band
|
||||||
buf.write_str("<span class=\"out-of-band\">");
|
buf.write_str("<span class=\"out-of-band\">");
|
||||||
|
|
|
@ -3061,3 +3061,28 @@ function hideThemeButtonState() {
|
||||||
window.onhashchange = onHashChange;
|
window.onhashchange = onHashChange;
|
||||||
setupSearchLoader();
|
setupSearchLoader();
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
function copy_path(but) {
|
||||||
|
var parent = but.parentElement;
|
||||||
|
var path = [];
|
||||||
|
|
||||||
|
onEach(parent.childNodes, function(child) {
|
||||||
|
if (child.tagName === 'A') {
|
||||||
|
path.push(child.textContent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var el = document.createElement('textarea');
|
||||||
|
el.value = 'use ' + path.join('::') + ';';
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
// To not make it appear on the screen.
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
|
||||||
|
document.body.appendChild(el);
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
|
||||||
|
but.textContent = '✓';
|
||||||
|
}
|
||||||
|
|
|
@ -33,3 +33,8 @@ rules.
|
||||||
/* Since there is no toggle (the "[-]") when JS is disabled, no need for this margin either. */
|
/* Since there is no toggle (the "[-]") when JS is disabled, no need for this margin either. */
|
||||||
margin-left: 0 !important;
|
margin-left: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#copy-path {
|
||||||
|
/* It requires JS to work so no need to display it in this case. */
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
|
@ -1316,14 +1316,7 @@ h4 > .notable-traits {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.help-button {
|
#theme-picker, #settings-menu, .help-button, #copy-path {
|
||||||
right: 30px;
|
|
||||||
font-family: "Fira Sans", Arial, sans-serif;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 17px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#theme-picker, #settings-menu, .help-button {
|
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
width: 27px;
|
width: 27px;
|
||||||
height: 29px;
|
height: 29px;
|
||||||
|
@ -1332,6 +1325,22 @@ h4 > .notable-traits {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.help-button {
|
||||||
|
right: 30px;
|
||||||
|
font-family: "Fira Sans", Arial, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 17px;
|
||||||
|
padding-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#copy-path {
|
||||||
|
height: 30px;
|
||||||
|
font-size: 18px;
|
||||||
|
margin-left: 10px;
|
||||||
|
padding: 0 6px;
|
||||||
|
width: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
#theme-choices {
|
#theme-choices {
|
||||||
display: none;
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
|
@ -498,7 +498,7 @@ kbd {
|
||||||
box-shadow-color: #c6cbd1;
|
box-shadow-color: #c6cbd1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#theme-picker, #settings-menu, .help-button {
|
#theme-picker, #settings-menu, .help-button, #copy-path {
|
||||||
border-color: #5c6773;
|
border-color: #5c6773;
|
||||||
background-color: #0f1419;
|
background-color: #0f1419;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
@ -510,7 +510,8 @@ kbd {
|
||||||
|
|
||||||
#theme-picker:hover, #theme-picker:focus,
|
#theme-picker:hover, #theme-picker:focus,
|
||||||
#settings-menu:hover, #settings-menu:focus,
|
#settings-menu:hover, #settings-menu:focus,
|
||||||
.help-button:hover, .help-button:focus {
|
.help-button:hover, .help-button:focus,
|
||||||
|
#copy-path:hover, #copy-path:focus {
|
||||||
border-color: #e0e0e0;
|
border-color: #e0e0e0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -388,7 +388,7 @@ kbd {
|
||||||
box-shadow-color: #c6cbd1;
|
box-shadow-color: #c6cbd1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#theme-picker, #settings-menu, .help-button {
|
#theme-picker, #settings-menu, .help-button, #copy-path {
|
||||||
border-color: #e0e0e0;
|
border-color: #e0e0e0;
|
||||||
background: #f0f0f0;
|
background: #f0f0f0;
|
||||||
color: #000;
|
color: #000;
|
||||||
|
@ -396,7 +396,8 @@ kbd {
|
||||||
|
|
||||||
#theme-picker:hover, #theme-picker:focus,
|
#theme-picker:hover, #theme-picker:focus,
|
||||||
#settings-menu:hover, #settings-menu:focus,
|
#settings-menu:hover, #settings-menu:focus,
|
||||||
.help-button:hover, .help-button:focus {
|
.help-button:hover, .help-button:focus,
|
||||||
|
#copy-path:hover, #copy-path:focus {
|
||||||
border-color: #ffb900;
|
border-color: #ffb900;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -380,14 +380,15 @@ kbd {
|
||||||
box-shadow-color: #c6cbd1;
|
box-shadow-color: #c6cbd1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#theme-picker, #settings-menu, .help-button {
|
#theme-picker, #settings-menu, .help-button, #copy-path {
|
||||||
border-color: #e0e0e0;
|
border-color: #e0e0e0;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#theme-picker:hover, #theme-picker:focus,
|
#theme-picker:hover, #theme-picker:focus,
|
||||||
#settings-menu:hover, #settings-menu:focus,
|
#settings-menu:hover, #settings-menu:focus,
|
||||||
.help-button:hover, .help-button:focus {
|
.help-button:hover, .help-button:focus,
|
||||||
|
#copy-path:hover, #copy-path:focus {
|
||||||
border-color: #717171;
|
border-color: #717171;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue