This commit is contained in:
Saoud Rizwan
2024-10-01 21:09:09 -04:00
parent 2f08aed301
commit f3fe7c9f5a
3 changed files with 21 additions and 9 deletions

View File

@@ -259,7 +259,10 @@ export class ClaudeDev {
lastMessage.text = text lastMessage.text = text
lastMessage.partial = false lastMessage.partial = false
await this.saveClaudeMessages() await this.saveClaudeMessages()
await this.providerRef.deref()?.postStateToWebview() // await this.providerRef.deref()?.postStateToWebview()
await this.providerRef
.deref()
?.postMessageToWebview({ type: "partialMessage", partialMessage: lastMessage })
} else { } else {
// this is a new partial=false message, so add it like normal // this is a new partial=false message, so add it like normal
this.askResponse = undefined 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 // instead of streaming partialMessage events, we do a save and post like normal to persist to disk
await this.saveClaudeMessages() 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 { } else {
// this is a new partial=false message, so add it like normal // this is a new partial=false message, so add it like normal
const sayTs = Date.now() const sayTs = Date.now()

View File

@@ -40,6 +40,7 @@ const ChatRow = memo(
useEffect(() => { useEffect(() => {
// used for partials, command output, etc. // 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 const isInitialRender = prevHeightRef.current === 0 // prevents scrolling when new element is added since we already scroll for that
// height starts off at Infinity // height starts off at Infinity
if (isLast && height !== 0 && height !== Infinity && height !== prevHeightRef.current) { if (isLast && height !== 0 && height !== Infinity && height !== prevHeightRef.current) {

View File

@@ -508,16 +508,21 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
taskMsgTsRef.current = task.ts taskMsgTsRef.current = task.ts
const timer = setTimeout(() => { const timer = setTimeout(() => {
scrollToBottomSmooth() scrollToBottomSmooth()
lastMsgIndexScrolledOn.current = visibleMessages.length - 1
}, 50) }, 50)
return () => clearTimeout(timer) return () => clearTimeout(timer)
} }
}, [task, scrollToBottomSmooth]) }, [task, scrollToBottomSmooth, visibleMessages.length])
const handleRowHeightChange = useCallback(() => { const handleRowHeightChange = useCallback(
if (isAtBottomRef.current) { (index: number) => {
scrollToBottomSmooth() if (isAtBottomRef.current) {
} scrollToBottomSmooth()
}, [scrollToBottomSmooth]) lastMsgIndexScrolledOn.current = index
}
},
[scrollToBottomSmooth]
)
const placeholderText = useMemo(() => { const placeholderText = useMemo(() => {
const text = task ? "Type a message (@ to add context)..." : "Type your task here (@ to add context)..." 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)} onToggleExpand={() => toggleRowExpansion(message.ts)}
lastModifiedMessage={modifiedMessages.at(-1)} lastModifiedMessage={modifiedMessages.at(-1)}
isLast={index === visibleMessages.length - 1} isLast={index === visibleMessages.length - 1}
onHeightChange={handleRowHeightChange} onHeightChange={() => handleRowHeightChange(index)}
/> />
), ),
[expandedRows, modifiedMessages, visibleMessages.length, toggleRowExpansion, handleRowHeightChange] [expandedRows, modifiedMessages, visibleMessages.length, toggleRowExpansion, handleRowHeightChange]