From 0f914b1bf0c9f441c6b1bed7163b96faa027fd58 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Fri, 13 Sep 2024 03:42:09 -0400 Subject: [PATCH] Fix scroll behavior --- webview-ui/src/components/ChatView.tsx | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/webview-ui/src/components/ChatView.tsx b/webview-ui/src/components/ChatView.tsx index eedbc06..24074d2 100644 --- a/webview-ui/src/components/ChatView.tsx +++ b/webview-ui/src/components/ChatView.tsx @@ -431,27 +431,30 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie if (isCollapsing && isAtBottom) { const timer = setTimeout(() => { - if (virtuosoRef.current) { - virtuosoRef.current.scrollToIndex({ + virtuosoRef.current?.scrollToIndex({ + index: visibleMessages.length - 1, + align: "end", + }) + }, 0) + return () => clearTimeout(timer) + } else if (isLastMessage) { + if (isCollapsing) { + const timer = setTimeout(() => { + virtuosoRef.current?.scrollToIndex({ index: visibleMessages.length - 1, align: "end", }) - } - }, 0) - return () => clearTimeout(timer) - } - - if (!isCollapsing && isLastMessage) { - const timer = setTimeout(() => { - if (virtuosoRef.current) { - virtuosoRef.current.scrollToIndex({ + }, 0) + return () => clearTimeout(timer) + } else { + const timer = setTimeout(() => { + virtuosoRef.current?.scrollToIndex({ index: visibleMessages.length - 1, align: "start", - behavior: "smooth", }) - } - }, 0) - return () => clearTimeout(timer) + }, 0) + return () => clearTimeout(timer) + } } }, [isAtBottom, visibleMessages, expandedRows]