Skip to content

Commit 1bbb816

Browse files
committed
Prevent jumps when selecting one or many lines
1 parent 71cf364 commit 1bbb816

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/librustdoc/html/static/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,21 @@ function getSearchElement() {
401401
var prev_line_id = 0;
402402

403403
var set_fragment = function(name) {
404+
var x = window.scrollX,
405+
y = window.scrollY;
404406
if (browserSupportsHistoryApi()) {
405407
history.replaceState(null, null, "#" + name);
406408
highlightSourceLines();
407409
} else {
408410
location.replace("#" + name);
409411
}
412+
// Prevent jumps when selecting one or many lines
413+
window.scrollTo(x, y);
410414
};
411415

412416
return function(ev) {
413417
var cur_line_id = parseInt(ev.target.id, 10);
418+
ev.preventDefault();
414419

415420
if (ev.shiftKey && prev_line_id) {
416421
// Swap selection if needed

0 commit comments

Comments
 (0)