fix: prevent stale windowStart when switching conversations

This commit is contained in:
2026-03-06 21:06:14 -08:00
committed by Naomi Carrigan
parent 93b3aa379c
commit e9a9ffc9ab
+14 -7
View File
@@ -59,20 +59,27 @@
currentConversationId = newId;
// Peek at the saved position to set windowStart before the first tick,
// preventing a stale windowStart from a previous conversation leaving
// visibleLines empty (windowStart >= lines.length).
const savedPosition = claudeStore.getScrollPosition(newId);
if (savedPosition === -1) {
// Will auto-scroll: pin the window to the tail of the new conversation
shouldAutoScroll = true;
windowStart = Math.max(0, lines.length - WINDOW_SIZE);
} else {
// Will restore a specific position: always start from the top of history
shouldAutoScroll = false;
windowStart = 0;
}
// Restore scroll position for the new conversation after DOM updates
await tick();
if (terminalElement) {
const savedPosition = claudeStore.getScrollPosition(newId);
isRestoringScroll = true;
if (savedPosition === -1) {
// Auto-scroll to bottom — window reactive statement will advance windowStart
shouldAutoScroll = true;
terminalElement.scrollTop = terminalElement.scrollHeight;
} else {
// Restore to saved position — show from the beginning of history
windowStart = 0;
shouldAutoScroll = false;
await tick();
terminalElement.scrollTop = savedPosition;
}
// Small delay to prevent the scroll handler from overriding our restore