Skip to content

Commit 8c47848

Browse files
last scroll attempt
1 parent 298d7d0 commit 8c47848

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

script.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,18 +1100,18 @@ if __name__ == "__main__":
11001100
const currentScroll = container.scrollTop;
11011101
const scrollHeight = container.scrollHeight;
11021102

1103-
// For lines near the bottom, ensure we can see them fully
1103+
// Account for bottom padding in max scroll calculation
11041104
const bottomBuffer = 45; // Extra space at bottom (matches CSS padding)
1105-
const maxScroll = scrollHeight - containerHeight;
1105+
const effectiveMaxScroll = scrollHeight - containerHeight;
11061106

11071107
// Check if this is a line being added near the bottom
11081108
const distanceFromBottom = scrollHeight - (lineOffsetTop + lineHeight);
11091109

1110-
if (distanceFromBottom < containerHeight / 3) {
1111-
// Line is in bottom third - scroll to show it with buffer
1112-
const targetScroll = Math.min(maxScroll, lineOffsetTop - containerHeight + lineHeight + bottomBuffer);
1110+
if (distanceFromBottom < containerHeight / 2) {
1111+
// Line is in bottom half - ensure it's visible with buffer
1112+
const targetScroll = lineOffsetTop - containerHeight + lineHeight + bottomBuffer;
11131113
container.scrollTo({
1114-
top: Math.max(0, targetScroll),
1114+
top: Math.max(0, Math.min(effectiveMaxScroll, targetScroll)),
11151115
behavior: 'auto'
11161116
});
11171117
} else {
@@ -1130,9 +1130,9 @@ if __name__ == "__main__":
11301130
finalTarget = scrollTarget - extraOffset;
11311131
}
11321132

1133-
// Smoothly scroll to the target position
1133+
// Always respect the effective max scroll limit
11341134
container.scrollTo({
1135-
top: Math.max(0, Math.min(maxScroll, finalTarget)),
1135+
top: Math.max(0, Math.min(effectiveMaxScroll, finalTarget)),
11361136
behavior: 'auto'
11371137
});
11381138
}

0 commit comments

Comments
 (0)