From 71a249c08aba3e9685980cf1fe66f9ad7f2deb91 Mon Sep 17 00:00:00 2001 From: Dorian Date: Tue, 3 Mar 2026 23:15:57 +0000 Subject: [PATCH] feat(chat): add scroll position memory per conversation (M8.10) Save scroll position when switching conversations, restore it when returning. Uses a session-only Map. Co-Authored-By: Claude Opus 4.6 --- .../app/src/components/chat/ChatWindow.vue | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/app/src/components/chat/ChatWindow.vue b/packages/app/src/components/chat/ChatWindow.vue index 46894831..4276409a 100644 --- a/packages/app/src/components/chat/ChatWindow.vue +++ b/packages/app/src/components/chat/ChatWindow.vue @@ -137,6 +137,27 @@ const codeContext = useCodeContext() const messageListRef = ref(null) const chatSearchRef = ref | null>(null) +// Scroll position memory per conversation +const scrollPositions = new Map() + +function saveScrollPosition() { + const el = messageListRef.value + const id = chatStore.activeConversationId + if (el && id) { + scrollPositions.set(id, el.scrollTop) + } +} + +function restoreScrollPosition(convId: string) { + const saved = scrollPositions.get(convId) + if (saved !== undefined) { + nextTick(() => { + const el = messageListRef.value + if (el) el.scrollTop = saved + }) + } +} + function scrollToMessageIndex(index: number) { virtualizer.value.scrollToIndex(index, { align: 'center' }) } @@ -313,6 +334,15 @@ function scrollToBottom() { }) } +// Save/restore scroll position on conversation switch +watch( + () => chatStore.activeConversationId, + (newId, oldId) => { + if (oldId) saveScrollPosition() + if (newId) restoreScrollPosition(newId) + } +) + watch( () => messages.value.length, () => scrollToBottom()