generated from nhcarrigan/template
fix: prevent stale windowStart when switching conversations
This commit is contained in:
@@ -59,20 +59,27 @@
|
|||||||
|
|
||||||
currentConversationId = newId;
|
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
|
// Restore scroll position for the new conversation after DOM updates
|
||||||
await tick();
|
await tick();
|
||||||
if (terminalElement) {
|
if (terminalElement) {
|
||||||
const savedPosition = claudeStore.getScrollPosition(newId);
|
|
||||||
isRestoringScroll = true;
|
isRestoringScroll = true;
|
||||||
if (savedPosition === -1) {
|
if (savedPosition === -1) {
|
||||||
// Auto-scroll to bottom — window reactive statement will advance windowStart
|
|
||||||
shouldAutoScroll = true;
|
|
||||||
terminalElement.scrollTop = terminalElement.scrollHeight;
|
terminalElement.scrollTop = terminalElement.scrollHeight;
|
||||||
} else {
|
} else {
|
||||||
// Restore to saved position — show from the beginning of history
|
|
||||||
windowStart = 0;
|
|
||||||
shouldAutoScroll = false;
|
|
||||||
await tick();
|
|
||||||
terminalElement.scrollTop = savedPosition;
|
terminalElement.scrollTop = savedPosition;
|
||||||
}
|
}
|
||||||
// Small delay to prevent the scroll handler from overriding our restore
|
// Small delay to prevent the scroll handler from overriding our restore
|
||||||
|
|||||||
Reference in New Issue
Block a user