From 55a5e8bc1c7e460c07560ea7695be0330416c161 Mon Sep 17 00:00:00 2001 From: Naman Kumar Date: Thu, 24 Oct 2024 14:42:46 +0530 Subject: [PATCH] Reset editor intent on new chat and empty editor value (#5991) This PR solves a bug and implements a minor feature. Well call it bugfix or feature whatever. Right now if the intent of chat is set to anything search/chat/edit/insert and you create a new chat, the intent is not reset. why? because the react component is not re-rendered and its key={n=index}, obviously the index stays 0 when you create a new chat. So this PR: 1. resets the intent when the input is cleared. 2. resets the intent when the message is changes. ## Test plan - change the intent, clear the input, the intent should reset - change the intent, submit the message, create a new chat, the intent should reset. ## Changelog --- .../messageCell/human/editor/HumanMessageEditor.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx b/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx index c9dd35a5bee..0ce8cb5a0e7 100644 --- a/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx +++ b/vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.tsx @@ -119,6 +119,18 @@ export const HumanMessageEditor: FunctionComponent<{ initialIntent || (experimentalOneBoxEnabled ? undefined : 'chat') ) + useEffect(() => { + // reset the input box intent when the editor is cleared + if (isEmptyEditorValue) { + setSubmitIntent(undefined) + } + }, [isEmptyEditorValue]) + + useEffect(() => { + // set the input box intent when the message is changed or a new chat is created + setSubmitIntent(initialIntent) + }, [initialIntent]) + const onSubmitClick = useCallback( (intent?: ChatMessage['intent']) => { if (submitState === 'emptyEditorValue') {