-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent sending empty message #126
Conversation
5ad6a80
to
6aab0e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brichet Thanks! One minor comment below.
// Do not send empty messages, and avoid adding new line in empty message. | ||
if (!input.trim()) { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handler only sends the message if !input.trim()
, but the SendButton
component is enabled by a different condition (when input.length >= 0
).
<SendButton
model={model}
sendWithShiftEnter={sendWithShiftEnter}
inputExists={input.length > 0}
onSend={onSend}
hideIncludeSelection={hideIncludeSelection}
hasButtonOnLeft={!!props.onCancel}
/>
Currently, if the input contains only white space, the send button will be enabled (which shouldn't happen), but pressing Enter/Shift-Enter does nothing. This is a difference in behavior caused by using two separate state variables.
I recommend defining a new local variable const inputExists = !!input.trim()
in the component's top scope, and using that variable in both the handler & the send button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in b28a698
The condition to disable the button was also applied to the 'cancel' button (visible when editing a message). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brichet TY! Great work
Fixes #118
Port jupyterlab/jupyter-ai#946
EDIT