Skip to content
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

Fix send via keyboard after sending slash command with arguments #850

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/jupyter-ai/src/components/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ export function ChatInput(props: ChatInputProps): JSX.Element {
setCurrSlashCommand(matchedSlashCommand && matchedSlashCommand[0]);
}, [props.value]);

/**
* Effect: ensure that the `highlighted` is never `true` when `open` is
* `false`.
*
* For context: https://github.com/jupyterlab/jupyter-ai/issues/849
*/
useEffect(() => {
if (!open && highlighted) {
setHighlighted(false);
}
}, [open, highlighted]);

// TODO: unify the `onSend` implementation in `chat.tsx` and here once text
// selection is refactored.
function onSend() {
Expand Down Expand Up @@ -231,24 +243,12 @@ export function ChatInput(props: ChatInputProps): JSX.Element {
/**
* On highlight change: set `highlighted` to whether an option is
* highlighted by the user.
*
* This isn't called when an option is selected for some reason, so we
* need to call `setHighlighted(false)` in `onClose()`.
*/
(_, highlightedOption) => {
setHighlighted(!!highlightedOption);
}
}
onClose={
/**
* On close: set `highlighted` to `false` and close the popup by
* setting `open` to `false`.
*/
() => {
setHighlighted(false);
setOpen(false);
}
}
onClose={() => setOpen(false)}
// set this to an empty string to prevent the last selected slash
// command from being shown in blue
value=""
Expand Down
Loading