diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx
index cc560de74..de2c410f7 100644
--- a/gui/src/components/mainInput/InputToolbar.tsx
+++ b/gui/src/components/mainInput/InputToolbar.tsx
@@ -123,7 +123,7 @@ function InputToolbar(props: InputToolbarProps) {
<>
{
- // Check if the new focus target is within our InputBoxDiv
- queueMicrotask(() => {
+ const blurTimeout = useRef(null);
+ const cancelBlurTimeout = useCallback(() => {
+ if (blurTimeout.current) {
+ clearTimeout(blurTimeout.current);
+ blurTimeout.current = null;
+ }
+ }, [blurTimeout]);
+
+ const handleBlur = useCallback(
+ (e: React.FocusEvent) => {
if (isInEditMode) {
return;
}
+ // Check if the new focus target is within our InputBoxDiv
const currentTarget = e.currentTarget;
const relatedTarget = e.relatedTarget as Node | null;
if (relatedTarget && currentTarget?.contains(relatedTarget)) {
return;
}
+ // Otherwise give e.g. listboxes a chance to cancel the hiding
+ blurTimeout.current = setTimeout(() => {
+ setShouldHideToolbar(true);
+ }, 100);
+ },
+ [isInEditMode, blurTimeout],
+ );
- setShouldHideToolbar(true);
- });
- };
+ const handleFocus = useCallback(() => {
+ cancelBlurTimeout();
+ setShouldHideToolbar(false);
+ }, [cancelBlurTimeout]);
+
+ // TODO pass clear blur timeout to model and mode selectors
+ // Seems like unnecessary for now?
return (
{
- setShouldHideToolbar(false);
- }}
+ onFocus={handleFocus}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
onKeyUp={handleKeyUp}
@@ -239,35 +256,33 @@ function TipTapEditor(props: TipTapEditorProps) {
event.stopPropagation();
}}
/>
- {(shouldHideToolbar && !props.isMainInput) || (
- insertCharacterWithWhitespace("@")}
- lumpOpen={props.lumpOpen}
- setLumpOpen={props.setLumpOpen}
- onEnter={onEnterRef.current}
- onImageFileSelected={(file) => {
- handleImageFile(ideMessenger, file).then((result) => {
- if (!editor) {
- return;
- }
- if (result) {
- const [_, dataUrl] = result;
- const { schema } = editor.state;
- const node = schema.nodes.image.create({ src: dataUrl });
- editor.commands.command(({ tr }) => {
- tr.insert(0, node);
- return true;
- });
- }
- });
- }}
- disabled={isStreaming}
- />
- )}
+ insertCharacterWithWhitespace("@")}
+ lumpOpen={props.lumpOpen}
+ setLumpOpen={props.setLumpOpen}
+ onEnter={onEnterRef.current}
+ onImageFileSelected={(file) => {
+ handleImageFile(ideMessenger, file).then((result) => {
+ if (!editor) {
+ return;
+ }
+ if (result) {
+ const [_, dataUrl] = result;
+ const { schema } = editor.state;
+ const node = schema.nodes.image.create({ src: dataUrl });
+ editor.commands.command(({ tr }) => {
+ tr.insert(0, node);
+ return true;
+ });
+ }
+ });
+ }}
+ disabled={isStreaming}
+ />
{showDragOverMsg &&
diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx
index 338e0b8ca..0e14adfad 100644
--- a/gui/src/components/modelSelection/ModeSelect.tsx
+++ b/gui/src/components/modelSelection/ModeSelect.tsx
@@ -63,10 +63,13 @@ function ModeSelect() {
// Switch to chat mode if agent mode is selected but not supported
useEffect(() => {
+ if (!selectedModel) {
+ return;
+ }
if (mode === "agent" && !agentModeSupported) {
dispatch(setMode("chat"));
}
- }, [mode, agentModeSupported, dispatch]);
+ }, [mode, agentModeSupported, dispatch, selectedModel]);
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {