Skip to content

Commit b230542

Browse files
committed
fix pod toggling scroll handling on source pages
1 parent 3b3de73 commit b230542

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

root/static/js/syntaxhighlighter.mjs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,32 @@ const findLines = (el, lines) => {
4444
const togglePod = (e) => {
4545
e.preventDefault();
4646

47-
const scrollTop = window.scrollTop;
47+
const scrollTop = window.scrollY;
4848

4949
let topLine;
5050
let topOffset;
51-
for (const line of document.querySelectorAll('.syntaxhighlighter .line')) {
52-
if (line.classList.contains('pod-line')) {
53-
continue;
54-
}
55-
else if (line.getClientRects().top < scrollTop) {
51+
for (const line of document.querySelectorAll('.syntaxhighlighter .container .line:not(.pod-line)')) {
52+
const lineTop = line.getBoundingClientRect().top;
53+
if (lineTop < 0) {
5654
topLine = line;
55+
topOffset = lineTop;
56+
}
57+
else {
58+
break;
5759
}
58-
}
59-
if (topLine) {
60-
topOffset = line.getClientRects().top - scrollTop;
6160
}
6261
for (const toggle of document.querySelectorAll('.pod-toggle')) {
6362
toggle.classList.toggle('pod-hidden');
6463
}
6564
if (topLine) {
65+
const diff = topLine.getBoundingClientRect().top - topOffset;
66+
6667
window.scrollTo({
67-
top: line.getClientRects().top - topOffset,
68+
top: scrollTop + diff,
6869
left: 0,
6970
behavior: "instant"
7071
});
7172
}
72-
7373
}
7474

7575
const hashLines = /^#L(\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*)$/;

0 commit comments

Comments
 (0)