Skip to content

Commit 91f3dd9

Browse files
authored
fix: preserve user input when selecting follow-up choices (RooCodeInc#7394)
1 parent c75f184 commit 91f3dd9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
166166
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
167167

168168
const [inputValue, setInputValue] = useState("")
169+
const inputValueRef = useRef(inputValue)
169170
const textAreaRef = useRef<HTMLTextAreaElement>(null)
170171
const [sendingDisabled, setSendingDisabled] = useState(false)
171172
const [selectedImages, setSelectedImages] = useState<string[]>([])
@@ -207,6 +208,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
207208
clineAskRef.current = clineAsk
208209
}, [clineAsk])
209210

211+
// Keep inputValueRef in sync with inputValue state
212+
useEffect(() => {
213+
inputValueRef.current = inputValue
214+
}, [inputValue])
215+
210216
useEffect(() => {
211217
isMountedRef.current = true
212218
return () => {
@@ -1493,7 +1499,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
14931499
return currentValue !== "" ? `${currentValue} \n${suggestion.answer}` : suggestion.answer
14941500
})
14951501
} else {
1502+
// Don't clear the input value when sending a follow-up choice
1503+
// The message should be sent but the text area should preserve what the user typed
1504+
const preservedInput = inputValueRef.current
14961505
handleSendMessage(suggestion.answer, [])
1506+
// Restore the input value after sending
1507+
setInputValue(preservedInput)
14971508
}
14981509
},
14991510
[handleSendMessage, setInputValue, switchToMode, alwaysAllowModeSwitch, clineAsk, markFollowUpAsAnswered],

0 commit comments

Comments
 (0)