Skip to content

Commit de4328b

Browse files
committed
fix scrolling to highlighted lines on source view
getClientRects returns an array, and its values are relative to the viewport. scrollIntoView is much easier to use for this.
1 parent a01bd12 commit de4328b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

root/static/js/syntaxhighlighter.mjs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,10 @@ if (source) {
379379
for (const toggle of document.querySelectorAll('.pod-toggle')) {
380380
toggle.classList.remove('pod-hidden');
381381
}
382-
window.scrollTo({
383-
top: lines[0].getClientRects().top,
384-
left: 0,
385-
behavior: 'smooth'
386-
});
387382
}
383+
lines[0].scrollIntoView({
384+
behavior: 'smooth',
385+
});
388386
});
389387
}
390388

@@ -395,10 +393,8 @@ const line_hash = document.location.hash.match(/^(#L\d+)(-|,|$)/);
395393
if (line_hash) {
396394
const el = document.querySelector(line_hash[1]);
397395
if (el) {
398-
window.scrollTo({
399-
top: el.getClientRects().top,
400-
left: 0,
401-
behavior: 'smooth'
396+
el.scrollIntoView({
397+
behavior: 'instant',
402398
});
403399
}
404400
}

0 commit comments

Comments
 (0)