Skip to content

Commit 14f350c

Browse files
authored
Merge pull request #3271 from metacpan/haarg/fix-source-scroll
fix scrolling to highlighted lines on source view
2 parents 2a668b0 + de4328b commit 14f350c

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)