fix: preserve user input when selecting follow-up choices (#7394)

This commit is contained in:
Daniel 2025-08-25 16:18:08 -05:00 committed by GitHub
parent c75f184022
commit 91f3dd90fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -166,6 +166,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
const [inputValue, setInputValue] = useState("")
const inputValueRef = useRef(inputValue)
const textAreaRef = useRef<HTMLTextAreaElement>(null)
const [sendingDisabled, setSendingDisabled] = useState(false)
const [selectedImages, setSelectedImages] = useState<string[]>([])
@ -207,6 +208,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
clineAskRef.current = clineAsk
}, [clineAsk])
// Keep inputValueRef in sync with inputValue state
useEffect(() => {
inputValueRef.current = inputValue
}, [inputValue])
useEffect(() => {
isMountedRef.current = true
return () => {
@ -1493,7 +1499,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
return currentValue !== "" ? `${currentValue} \n${suggestion.answer}` : suggestion.answer
})
} else {
// Don't clear the input value when sending a follow-up choice
// The message should be sent but the text area should preserve what the user typed
const preservedInput = inputValueRef.current
handleSendMessage(suggestion.answer, [])
// Restore the input value after sending
setInputValue(preservedInput)
}
},
[handleSendMessage, setInputValue, switchToMode, alwaysAllowModeSwitch, clineAsk, markFollowUpAsAnswered],