From 51c0c00416ceb7388b478f6cdff927a2839b0846 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 20 Feb 2024 23:43:56 -0800 Subject: [PATCH] fix another special case ai-chat close + cmd focus issue --- src/app/workspace/cmdinput/aichat.tsx | 4 ++-- src/app/workspace/cmdinput/textareainput.tsx | 2 +- src/models/input.ts | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/workspace/cmdinput/aichat.tsx b/src/app/workspace/cmdinput/aichat.tsx index 47ca309c1..f3a71f47f 100644 --- a/src/app/workspace/cmdinput/aichat.tsx +++ b/src/app/workspace/cmdinput/aichat.tsx @@ -5,7 +5,7 @@ import * as React from "react"; import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; import { GlobalModel } from "@/models"; -import { isBlank } from "@/util"; +import { isBlank } from "@/util/util"; import { boundMethod } from "autobind-decorator"; import cn from "classnames"; import { For } from "tsx-control-statements/components"; @@ -92,7 +92,7 @@ class AIChat extends React.Component<{}, {}> { if (checkKeyPressed(waveEvent, "Escape")) { e.preventDefault(); e.stopPropagation(); - inputModel.closeAIAssistantChat(); + inputModel.closeAIAssistantChat(true); } if (checkKeyPressed(waveEvent, "Ctrl:l")) { diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index 14e575467..6ca454e03 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -232,7 +232,7 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: () if (inputModel.inputMode.get() != null) { inputModel.resetInputMode(); } - inputModel.closeAIAssistantChat(); + inputModel.closeAIAssistantChat(true); return; } if (checkKeyPressed(waveEvent, "Cmd:e")) { diff --git a/src/models/input.ts b/src/models/input.ts index 1aef59236..96ea01c6d 100644 --- a/src/models/input.ts +++ b/src/models/input.ts @@ -618,13 +618,17 @@ class InputModel { })(); } - closeAIAssistantChat(): void { + // pass true to give focus to the input (e.g. if this is an 'active' close of the chat) + // when resetting the input (when switching screens, don't give focus) + closeAIAssistantChat(giveFocus: boolean): void { if (!this.aIChatShow.get()) { return; } mobx.action(() => { this.aIChatShow.set(false); - this.giveFocus(); + if (giveFocus) { + this.giveFocus(); + } })(); } @@ -726,7 +730,7 @@ class InputModel { resetInput(): void { mobx.action(() => { this.setHistoryShow(false); - this.closeAIAssistantChat(); + this.closeAIAssistantChat(false); this.infoShow.set(false); this.inputMode.set(null); this.resetHistory();