From 6aab0e654bd319e22a0b481fafe664b3c1e0ce2c Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Mon, 16 Dec 2024 22:28:45 +0100 Subject: [PATCH 1/3] Don't send empty message --- .../jupyter-chat/src/components/chat-input.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/jupyter-chat/src/components/chat-input.tsx b/packages/jupyter-chat/src/components/chat-input.tsx index 40e27b9b..82460c27 100644 --- a/packages/jupyter-chat/src/components/chat-input.tsx +++ b/packages/jupyter-chat/src/components/chat-input.tsx @@ -130,16 +130,22 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element { return; } - // do not send the message if the user was selecting a suggested command from the + // Do not send the message if the user was selecting a suggested command from the // Autocomplete component. if (highlighted) { return; } + // Do not send empty messages, and avoid adding new line in empty message. + if (!input.trim()) { + event.stopPropagation(); + event.preventDefault(); + return; + } + if ( - event.key === 'Enter' && - ((sendWithShiftEnter && event.shiftKey) || - (!sendWithShiftEnter && !event.shiftKey)) + (sendWithShiftEnter && event.shiftKey) || + (!sendWithShiftEnter && !event.shiftKey) ) { onSend(); event.stopPropagation(); From b28a6983207a22119ef03ca4f5ea251ef62c1252 Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Wed, 18 Dec 2024 08:29:57 +0100 Subject: [PATCH 2/3] Same condition to prevent sending message with keyboard or button Co-authored-by: david qiu <44106031+dlqqq@users.noreply.github.com> --- packages/jupyter-chat/src/components/chat-input.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/jupyter-chat/src/components/chat-input.tsx b/packages/jupyter-chat/src/components/chat-input.tsx index 82460c27..b29a4d3d 100644 --- a/packages/jupyter-chat/src/components/chat-input.tsx +++ b/packages/jupyter-chat/src/components/chat-input.tsx @@ -78,6 +78,8 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element { // controls whether the slash command autocomplete is open const [open, setOpen] = useState(false); + const inputExists = !!input.trim(); + /** * Effect: fetch the list of available autocomplete commands. */ @@ -137,7 +139,7 @@ export function ChatInput(props: ChatInput.IProps): JSX.Element { } // Do not send empty messages, and avoid adding new line in empty message. - if (!input.trim()) { + if (!inputExists) { event.stopPropagation(); event.preventDefault(); return; @@ -232,14 +234,14 @@ ${selection.source} {props.onCancel && ( 0} + inputExists={inputExists} onCancel={onCancel} /> )} 0} + inputExists={inputExists} onSend={onSend} hideIncludeSelection={hideIncludeSelection} hasButtonOnLeft={!!props.onCancel} From cbf7a3b33a1ce7f542b0031b992b201c7cb77c5b Mon Sep 17 00:00:00 2001 From: Nicolas Brichet Date: Wed, 18 Dec 2024 08:33:47 +0100 Subject: [PATCH 3/3] Do not disable the 'cancel edition' button --- packages/jupyter-chat/src/components/chat-input.tsx | 7 +------ .../jupyter-chat/src/components/input/cancel-button.tsx | 3 --- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/jupyter-chat/src/components/chat-input.tsx b/packages/jupyter-chat/src/components/chat-input.tsx index b29a4d3d..41a15b41 100644 --- a/packages/jupyter-chat/src/components/chat-input.tsx +++ b/packages/jupyter-chat/src/components/chat-input.tsx @@ -232,12 +232,7 @@ ${selection.source} ...params.InputProps, endAdornment: ( - {props.onCancel && ( - - )} + {props.onCancel && } void; }; @@ -22,11 +21,9 @@ export type CancelButtonProps = { */ export function CancelButton(props: CancelButtonProps): JSX.Element { const tooltip = 'Cancel edition'; - const disabled = !props.inputExists; return (