Skip to content

Commit

Permalink
Prevent jumps when selecting one or many lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dns2utf8 committed Nov 15, 2019
1 parent 71cf364 commit 1bbb816
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,21 @@ function getSearchElement() {
var prev_line_id = 0;

var set_fragment = function(name) {
var x = window.scrollX,
y = window.scrollY;
if (browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name);
highlightSourceLines();
} else {
location.replace("#" + name);
}
// Prevent jumps when selecting one or many lines
window.scrollTo(x, y);
};

return function(ev) {
var cur_line_id = parseInt(ev.target.id, 10);
ev.preventDefault();

if (ev.shiftKey && prev_line_id) {
// Swap selection if needed
Expand Down

0 comments on commit 1bbb816

Please sign in to comment.