Skip to content

Commit 6391e47

Browse files
jshasyphar
authored andcommitted
Add "y" shortcut for permalink
1 parent 5f1f09f commit 6391e47

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

static/menu.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,17 @@
235235
menu.firstElementChild.addEventListener("click", menuOnClick);
236236
}
237237
document.documentElement.addEventListener("keydown", menuKeyDown);
238+
document.documentElement.addEventListener("keydown", function(ev) {
239+
if (ev.key == "y") {
240+
let permalink = document.getElementById("permalink");
241+
if (document.location.hash != "") {
242+
permalink.href += "#" + document.location.hash;
243+
}
244+
// Note: It would be nicer to do history.replaceState here and avoid a page load
245+
// (that's what GitHub does), but the permalink goes through a redirect, so you wind up
246+
// with a weird URL like:
247+
// http://localhost:3000/crate/regex/1.3.1/target-redirect/x86_64-unknown-linux-gnu/regex/index.html
248+
permalink.click();
249+
}
250+
});
238251
})();

templates/rustdoc/topbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
{%- if metadata.version_or_latest == "latest" -%}
2626
<li class="pure-menu-item">
27-
<a href="{{permalink_path | safe}}" class="pure-menu-link description" title="Get a link to this specific version">
27+
<a href="{{permalink_path | safe}}" class="pure-menu-link description" id="permalink" title="Get a link to this specific version">
2828
{{ "link" | fas }} Permalink
2929
</a>
3030
</li>

0 commit comments

Comments
 (0)