From 3f5c40449acacc9e70d002fc83eae9f567e3b42d Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 9 Aug 2024 23:55:05 +0800 Subject: [PATCH] prevent send on empty input --- packages/jupyter-ai/src/components/chat-input.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/jupyter-ai/src/components/chat-input.tsx b/packages/jupyter-ai/src/components/chat-input.tsx index 4ab9bcd36..ddc2d4209 100644 --- a/packages/jupyter-ai/src/components/chat-input.tsx +++ b/packages/jupyter-ai/src/components/chat-input.tsx @@ -207,6 +207,7 @@ export function ChatInput(props: ChatInputProps): JSX.Element { props.chatHandler.sendMessage({ prompt, selection }); } + const inputExists = !!input.trim(); function handleKeyDown(event: React.KeyboardEvent) { if (event.key !== 'Enter') { return; @@ -218,6 +219,12 @@ export function ChatInput(props: ChatInputProps): JSX.Element { return; } + if (!inputExists) { + event.stopPropagation(); + event.preventDefault(); + return; + } + if ( event.key === 'Enter' && ((props.sendWithShiftEnter && event.shiftKey) || @@ -240,7 +247,6 @@ export function ChatInput(props: ChatInputProps): JSX.Element { ); - const inputExists = !!input.trim(); const sendButtonProps: SendButtonProps = { onSend, sendWithShiftEnter: props.sendWithShiftEnter,