diff options
author | Michael Howell <michael@notriddle.com> | 2022-10-27 11:16:30 -0700 |
---|---|---|
committer | Michael Howell <michael@notriddle.com> | 2022-10-31 13:59:52 -0700 |
commit | 07bb2f701e5bae0da724068bbce1920458df9cda (patch) | |
tree | e66ce28d1066147abc87224fde63b4f6c39d8075 /src/librustdoc/html/static/js/source-script.js | |
parent | 2afca78a0b03db144c5d8b9f8868feebfe096309 (diff) | |
download | rust-07bb2f701e5bae0da724068bbce1920458df9cda.tar.gz |
rustdoc: change `.src-line-numbers > span` to `.src-line-numbers > a`
This allows people to treat them like real links, such as right-click to
copy URL, and makes the line numbers in a scraped example work at all,
when before this commit was added, they had the clickable pointer cursor
but did not actually do anything when clicked.
Diffstat (limited to 'src/librustdoc/html/static/js/source-script.js')
-rw-r--r-- | src/librustdoc/html/static/js/source-script.js | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 0b9368dd899..5db768c1c57 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -157,7 +157,7 @@ function highlightSourceLines(match) { x.scrollIntoView(); } onEachLazy(document.getElementsByClassName("src-line-numbers"), e => { - onEachLazy(e.getElementsByTagName("span"), i_e => { + onEachLazy(e.getElementsByTagName("a"), i_e => { removeClass(i_e, "line-highlighted"); }); }); @@ -188,8 +188,13 @@ const handleSourceHighlight = (function() { return ev => { let cur_line_id = parseInt(ev.target.id, 10); - // It can happen when clicking not on a line number span. - if (isNaN(cur_line_id)) { + // This event handler is attached to the entire line number column, but it should only + // be run if one of the anchors is clicked. It also shouldn't do anything if the anchor + // is clicked with a modifier key (to open a new browser tab). + if (isNaN(cur_line_id) || + ev.ctrlKey || + ev.altKey || + ev.metaKey) { return; } ev.preventDefault(); |