Skip to content

Commit 613272d

Browse files
hopefully fix scroll padding issue
1 parent a2e2756 commit 613272d

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

diff-viz-styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
scrollbar-width: thin;
5353
scrollbar-color: #ccc #f5f5f5;
5454
overscroll-behavior-y: contain;
55-
padding-bottom: 30px;
55+
padding-bottom: 45px;
5656
}
5757

5858
/* Style scrollbar for Chrome, Safari and Opera */

script.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,27 +1098,44 @@ if __name__ == "__main__":
10981098
const containerHeight = container.clientHeight;
10991099
const lineHeight = lineEl.clientHeight;
11001100
const currentScroll = container.scrollTop;
1101+
const scrollHeight = container.scrollHeight;
11011102

1102-
// Center the line in the container
1103-
const scrollTarget = lineOffsetTop - (containerHeight / 2) + (lineHeight / 2);
1103+
// For lines near the bottom, ensure we can see them fully
1104+
const bottomBuffer = 45; // Extra space at bottom (matches CSS padding)
1105+
const maxScroll = scrollHeight - containerHeight;
11041106

1105-
// Determine scroll direction and add/subtract offset accordingly
1106-
const extraOffset = 30; // Extra pixels to ensure visibility
1107-
let finalTarget;
1107+
// Check if this is a line being added near the bottom
1108+
const distanceFromBottom = scrollHeight - (lineOffsetTop + lineHeight);
11081109

1109-
if (scrollTarget > currentScroll) {
1110-
// Scrolling down - add extra offset
1111-
finalTarget = scrollTarget + extraOffset;
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);
1113+
container.scrollTo({
1114+
top: Math.max(0, targetScroll),
1115+
behavior: 'smooth'
1116+
});
11121117
} else {
1113-
// Scrolling up - subtract extra offset
1114-
finalTarget = scrollTarget - extraOffset;
1118+
// Normal centering behavior for other lines
1119+
const scrollTarget = lineOffsetTop - (containerHeight / 2) + (lineHeight / 2);
1120+
1121+
// Determine scroll direction and add/subtract offset accordingly
1122+
const extraOffset = 30; // Extra pixels to ensure visibility
1123+
let finalTarget;
1124+
1125+
if (scrollTarget > currentScroll) {
1126+
// Scrolling down - add extra offset
1127+
finalTarget = scrollTarget + extraOffset;
1128+
} else {
1129+
// Scrolling up - subtract extra offset
1130+
finalTarget = scrollTarget - extraOffset;
1131+
}
1132+
1133+
// Smoothly scroll to the target position
1134+
container.scrollTo({
1135+
top: Math.max(0, Math.min(maxScroll, finalTarget)),
1136+
behavior: 'smooth'
1137+
});
11151138
}
1116-
1117-
// Smoothly scroll to the target position
1118-
container.scrollTo({
1119-
top: Math.max(0, finalTarget),
1120-
behavior: 'smooth'
1121-
});
11221139
}
11231140
}
11241141

0 commit comments

Comments
 (0)