Skip to content

Commit

Permalink
Do not let ai chat submit empty messages (#14771)
Browse files Browse the repository at this point in the history
fixed #14755

Signed-off-by: Jonas Helming <[email protected]>
  • Loading branch information
JonasHelming authored Jan 25, 2025
1 parent 445b35b commit 42e1556
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/ai-chat-ui/src/browser/chat-input-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
const onDeleteChangeSetElement = (index: number) => props.onDeleteChangeSetElement(props.chatModel.id, index);

const [inProgress, setInProgress] = React.useState(false);
const [isInputEmpty, setIsInputEmpty] = React.useState(true);
const [changeSetUI, setChangeSetUI] = React.useState(
() => props.chatModel.changeSet ? buildChangeSetUI(props.chatModel.changeSet, props.labelProvider, onDeleteChangeSet, onDeleteChangeSetElement) : undefined
);
Expand Down Expand Up @@ -212,6 +213,8 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
}
};
editor.getControl().onDidChangeModelContent(() => {
const value = editor.getControl().getValue();
setIsInputEmpty(!value || value.length === 0);
updateEditorHeight();
handleOnChange();
});
Expand Down Expand Up @@ -270,6 +273,9 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
}, [props.chatModel]);

function submit(value: string): void {
if (!value || value.trim().length === 0) {
return;
}
setInProgress(true);
props.onQuery(value);
if (editorRef.current) {
Expand Down Expand Up @@ -338,7 +344,8 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
submit(editorRef.current?.document.textEditorModel.getValue() || '');
}
},
className: 'codicon-send'
className: 'codicon-send',
disabled: isInputEmpty || !props.isEnabled
}];

return <div className='theia-ChatInput'>
Expand Down Expand Up @@ -446,6 +453,7 @@ interface Option {
title: string;
handler: () => void;
className: string;
disabled?: boolean;
}

const ChatInputOptions: React.FunctionComponent<ChatInputOptionsProps> = ({ leftOptions, rightOptions }) => (
Expand All @@ -454,7 +462,7 @@ const ChatInputOptions: React.FunctionComponent<ChatInputOptionsProps> = ({ left
{leftOptions.map((option, index) => (
<span
key={index}
className={`codicon ${option.className} option`}
className={`codicon ${option.className} option ${option.disabled ? 'disabled' : ''}`}
title={option.title}
onClick={option.handler}
/>
Expand All @@ -464,7 +472,7 @@ const ChatInputOptions: React.FunctionComponent<ChatInputOptionsProps> = ({ left
{rightOptions.map((option, index) => (
<span
key={index}
className={`codicon ${option.className} option`}
className={`codicon ${option.className} option ${option.disabled ? 'disabled' : ''}`}
title={option.title}
onClick={option.handler}
/>
Expand Down
6 changes: 6 additions & 0 deletions packages/ai-chat-ui/src/browser/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ div:last-child > .theia-ChatNode {
cursor: pointer;
}

.theia-ChatInputOptions .option.disabled {
cursor: default;
opacity: var(--theia-mod-disabled-opacity);
pointer-events: none;
}

.theia-ChatInputOptions .option:hover {
opacity: 1;
background-color: var(--theia-toolbar-hoverBackground);
Expand Down

0 comments on commit 42e1556

Please sign in to comment.