Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions webview-ui/src/components/chat/__tests__/ChatTextArea.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,38 @@ describe("ChatTextArea", () => {
expect(setInputValue).toHaveBeenCalledWith("Current input")
})

it("should preserve current input while assistant messages stream", () => {
const setInputValue = vi.fn()
const { container, rerender } = render(
<ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="Current input" />,
)
const textarea = container.querySelector("textarea")!

textarea.setSelectionRange(0, 0)
fireEvent.keyDown(textarea, { key: "ArrowUp" })
expect(setInputValue).toHaveBeenCalledWith("Third prompt")
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
filePaths: [],
openedTabs: [],
apiConfiguration: {
apiProvider: providerIdentifiers.anthropic,
},
taskHistory: [],
clineMessages: [
...mockClineMessages,
{ type: "say", say: "text", text: "Streaming assistant output", ts: 4000 },
],
cwd: "/test/workspace",
})
setInputValue.mockClear()
rerender(<ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="Third prompt" />)
textarea.setSelectionRange(textarea.value.length, textarea.value.length)

fireEvent.keyDown(textarea, { key: "ArrowDown" })

expect(setInputValue).toHaveBeenCalledWith("Current input")
})

it("should reset history navigation when user types", () => {
const setInputValue = vi.fn()
const { container } = render(
Expand Down
8 changes: 7 additions & 1 deletion webview-ui/src/components/chat/hooks/usePromptHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@

// Update prompt history when filtered history changes and reset navigation
useEffect(() => {
const historyChanged =
promptHistory.length !== filteredPromptHistory.length ||
promptHistory.some((prompt, index) => prompt !== filteredPromptHistory[index])

Check warning on line 76 in webview-ui/src/components/chat/hooks/usePromptHistory.ts

View workflow job for this annotation

GitHub Actions / mutation-diff

Mutation test advisory

webview-ui/src/components/chat/hooks/usePromptHistory.ts:76: Survived MethodExpression mutant (replacement: promptHistory.every((prompt, index) => prompt !== filteredPromptHistory[index])). See the job summary for the complete list and resolution guidance.

if (!historyChanged) return
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

setPromptHistory(filteredPromptHistory)
// Reset navigation state when switching between history sources
setHistoryIndex(-1)
setTempInput("")
}, [filteredPromptHistory])
}, [filteredPromptHistory, promptHistory])

// Reset history navigation when user types (but not when we're setting it programmatically)
const resetOnInputChange = useCallback(() => {
Expand Down
Loading