diff --git a/src/models/modals.ts b/src/models/modals.ts index 4c4dcfd99..cbd0554a4 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 0bf49e82c..898871b79 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() })