From f3fe7c9f5a3930ae25719188b3b360ad98829bdc Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:09:09 -0400 Subject: [PATCH] Fixes --- src/core/ClaudeDev.ts | 10 ++++++++-- webview-ui/src/components/chat/ChatRow.tsx | 1 + webview-ui/src/components/chat/ChatView.tsx | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/ClaudeDev.ts b/src/core/ClaudeDev.ts index afee473..7404694 100644 --- a/src/core/ClaudeDev.ts +++ b/src/core/ClaudeDev.ts @@ -259,7 +259,10 @@ export class ClaudeDev { lastMessage.text = text lastMessage.partial = false await this.saveClaudeMessages() - await this.providerRef.deref()?.postStateToWebview() + // await this.providerRef.deref()?.postStateToWebview() + await this.providerRef + .deref() + ?.postMessageToWebview({ type: "partialMessage", partialMessage: lastMessage }) } else { // this is a new partial=false message, so add it like normal this.askResponse = undefined @@ -337,7 +340,10 @@ export class ClaudeDev { // instead of streaming partialMessage events, we do a save and post like normal to persist to disk await this.saveClaudeMessages() - await this.providerRef.deref()?.postStateToWebview() + // await this.providerRef.deref()?.postStateToWebview() + await this.providerRef + .deref() + ?.postMessageToWebview({ type: "partialMessage", partialMessage: lastMessage }) // more performant than an entire postStateToWebview } else { // this is a new partial=false message, so add it like normal const sayTs = Date.now() diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index c46536d..ca218b8 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -40,6 +40,7 @@ const ChatRow = memo( useEffect(() => { // used for partials, command output, etc. + // NOTE: it's important we don't distinguish between partial or complete here since our scroll effects in chatview need to handle height change during partial -> complete const isInitialRender = prevHeightRef.current === 0 // prevents scrolling when new element is added since we already scroll for that // height starts off at Infinity if (isLast && height !== 0 && height !== Infinity && height !== prevHeightRef.current) { diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 6fe4a8a..c13733e 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -508,16 +508,21 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie taskMsgTsRef.current = task.ts const timer = setTimeout(() => { scrollToBottomSmooth() + lastMsgIndexScrolledOn.current = visibleMessages.length - 1 }, 50) return () => clearTimeout(timer) } - }, [task, scrollToBottomSmooth]) + }, [task, scrollToBottomSmooth, visibleMessages.length]) - const handleRowHeightChange = useCallback(() => { - if (isAtBottomRef.current) { - scrollToBottomSmooth() - } - }, [scrollToBottomSmooth]) + const handleRowHeightChange = useCallback( + (index: number) => { + if (isAtBottomRef.current) { + scrollToBottomSmooth() + lastMsgIndexScrolledOn.current = index + } + }, + [scrollToBottomSmooth] + ) const placeholderText = useMemo(() => { const text = task ? "Type a message (@ to add context)..." : "Type your task here (@ to add context)..." @@ -533,7 +538,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie onToggleExpand={() => toggleRowExpansion(message.ts)} lastModifiedMessage={modifiedMessages.at(-1)} isLast={index === visibleMessages.length - 1} - onHeightChange={handleRowHeightChange} + onHeightChange={() => handleRowHeightChange(index)} /> ), [expandedRows, modifiedMessages, visibleMessages.length, toggleRowExpansion, handleRowHeightChange]