Skip to content

Commit

Permalink
fix scrolling to highlighted lines on source view
Browse files Browse the repository at this point in the history
getClientRects returns an array, and its values are relative to the
viewport. scrollIntoView is much easier to use for this.
  • Loading branch information
haarg committed Jan 28, 2025
1 parent 3377389 commit 0ce5198
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions root/static/js/syntaxhighlighter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,10 @@ if (source) {
for (const toggle of document.querySelectorAll('.pod-toggle')) {
toggle.classList.remove('pod-hidden');
}
window.scrollTo({
top: lines[0].getClientRects().top,
left: 0,
behavior: 'smooth'
});
}
lines[0].scrollIntoView({
behavior: 'smooth',
});
});
}

Expand All @@ -395,10 +393,8 @@ const line_hash = document.location.hash.match(/^(#L\d+)(-|,|$)/);
if (line_hash) {
const el = document.querySelector(line_hash[1]);
if (el) {
window.scrollTo({
top: el.getClientRects().top,
left: 0,
behavior: 'smooth'
el.scrollIntoView({
behavior: 'instant',
});
}
}
Expand Down

0 comments on commit 0ce5198

Please sign in to comment.