Skip to content

Commit

Permalink
prevent enter from sending empty message
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchia committed Aug 9, 2024
1 parent 3afe37c commit 7415896
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/jupyter-ai/src/components/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>) {
if (event.key !== 'Enter') {
return;
Expand All @@ -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) ||
Expand All @@ -240,7 +247,6 @@ export function ChatInput(props: ChatInputProps): JSX.Element {
</span>
);

const inputExists = !!input.trim();
const sendButtonProps: SendButtonProps = {
onSend,
sendWithShiftEnter: props.sendWithShiftEnter,
Expand Down

0 comments on commit 7415896

Please sign in to comment.