From 73e5515e17535a717244f413fc142cd3dc401747 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Tue, 9 Apr 2024 11:48:34 -0700 Subject: [PATCH] when the window gets focus, if our mainview is session (and no modals are open), refocus either the cmdinput or the cmd (#562) --- src/models/modals.ts | 4 ++++ src/models/model.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/models/modals.ts b/src/models/modals.ts index 4c4dcfd9..cbd0554a 100644 --- a/src/models/modals.ts +++ b/src/models/modals.ts @@ -24,6 +24,10 @@ class ModalsModel { })(); callback && callback(); } + + hasOpenModals(): boolean { + return this.store.length > 0; + } } export { ModalsModel }; diff --git a/src/models/model.ts b/src/models/model.ts index 0bf49e82..898871b7 100644 --- a/src/models/model.ts +++ b/src/models/model.ts @@ -203,6 +203,7 @@ class Model { getApi().onNativeThemeUpdated(this.onNativeThemeUpdated.bind(this)); document.addEventListener("keydown", this.docKeyDownHandler.bind(this)); document.addEventListener("selectionchange", this.docSelectionChangeHandler.bind(this)); + window.addEventListener("focus", this.windowFocus.bind(this)); setTimeout(() => this.getClientDataLoop(1), 10); this.lineHeightEnv = { // defaults @@ -229,6 +230,12 @@ class Model { }); } + windowFocus(): void { + if (this.activeMainView.get() == "session" && !this.modalsModel.hasOpenModals()) { + this.refocus(); + } + } + fetchTerminalThemes() { const url = new URL(this.getBaseHostPort() + "/config/terminal-themes"); fetch(url, { method: "get", body: null, headers: this.getFetchHeaders() })