fix: disappearing user text when stopped (#1839)

This commit is contained in:
Wendy Tang
2025-03-25 10:08:01 -07:00
committed by GitHub
parent 17f8fc087a
commit a28a0d149f
2 changed files with 22 additions and 1 deletions

View File

@@ -255,6 +255,12 @@ export default function ChatView({
// isUserMessage also checks if the message is a toolConfirmationRequest
// check if the last message is a real user's message
if (lastMessage && isUserMessage(lastMessage) && !isToolResponse) {
// Get the text content from the last message before removing it
const textContent = lastMessage.content.find((c) => c.type === 'text')?.text || '';
// Set the text back to the input field
_setInput(textContent);
// Remove the last user message if it's the most recent one
if (messages.length > 1) {
setMessages(messages.slice(0, -1));
@@ -433,6 +439,8 @@ export default function ChatView({
isLoading={isLoading}
onStop={onStopGoose}
commandHistory={commandHistory}
value={_input}
onValueChange={_setInput}
/>
<BottomMenu hasMessages={hasMessages} setView={setView} />
</div>

View File

@@ -8,6 +8,8 @@ interface InputProps {
isLoading?: boolean;
onStop?: () => void;
commandHistory?: string[];
value?: string;
onValueChange?: (value: string) => void;
}
export default function Input({
@@ -15,8 +17,19 @@ export default function Input({
isLoading = false,
onStop,
commandHistory = [],
value: controlledValue,
onValueChange,
}: InputProps) {
const [value, setValue] = useState('');
const [internalValue, setInternalValue] = useState('');
// Use controlled value if provided, otherwise use internal state
const value = controlledValue !== undefined ? controlledValue : internalValue;
const setValue = (newValue: string) => {
if (controlledValue !== undefined && onValueChange) {
onValueChange(newValue);
} else {
setInternalValue(newValue);
}
};
// State to track if the IME is composing (i.e., in the middle of Japanese IME input)
const [isComposing, setIsComposing] = useState(false);
const [historyIndex, setHistoryIndex] = useState(-1);