Skip to content

Commit a2e2756

Browse files
fix scrolling logic to not hide new lines, hopefully
1 parent 2d83504 commit a2e2756

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

script.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,13 +1097,26 @@ if __name__ == "__main__":
10971097
const lineOffsetTop = lineEl.offsetTop;
10981098
const containerHeight = container.clientHeight;
10991099
const lineHeight = lineEl.clientHeight;
1100+
const currentScroll = container.scrollTop;
11001101

11011102
// Center the line in the container
11021103
const scrollTarget = lineOffsetTop - (containerHeight / 2) + (lineHeight / 2);
11031104

1105+
// Determine scroll direction and add/subtract offset accordingly
1106+
const extraOffset = 30; // Extra pixels to ensure visibility
1107+
let finalTarget;
1108+
1109+
if (scrollTarget > currentScroll) {
1110+
// Scrolling down - add extra offset
1111+
finalTarget = scrollTarget + extraOffset;
1112+
} else {
1113+
// Scrolling up - subtract extra offset
1114+
finalTarget = scrollTarget - extraOffset;
1115+
}
1116+
11041117
// Smoothly scroll to the target position
11051118
container.scrollTo({
1106-
top: Math.max(0, scrollTarget),
1119+
top: Math.max(0, finalTarget),
11071120
behavior: 'smooth'
11081121
});
11091122
}

0 commit comments

Comments
 (0)