From 9eb746196432d4e9b0f163c25023ad4d37ab9b05 Mon Sep 17 00:00:00 2001 From: Red J Adaya Date: Thu, 14 Mar 2024 09:51:16 +0800 Subject: [PATCH] Close modals when pressing Escape (#433) * remove clearmodals mothed as it's no longer needed * close modals on ECS --- src/app/common/modals/alert.tsx | 2 +- src/models/bookmarks.ts | 2 +- src/models/clientsettingsview.ts | 10 ++++++++ src/models/connectionsview.ts | 10 ++++++++ src/models/historyview.ts | 2 +- src/models/modals.ts | 3 ++- src/models/model.ts | 41 ++++++-------------------------- 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/app/common/modals/alert.tsx b/src/app/common/modals/alert.tsx index f128f26d..714869ae 100644 --- a/src/app/common/modals/alert.tsx +++ b/src/app/common/modals/alert.tsx @@ -44,7 +44,7 @@ class AlertModal extends React.Component<{}, {}> { {message?.message} - + void) { mobx.action(() => { this.store.pop(); })(); + callback && callback(); } } diff --git a/src/models/model.ts b/src/models/model.ts index a1d0069a..ea0128bc 100644 --- a/src/models/model.ts +++ b/src/models/model.ts @@ -357,7 +357,6 @@ class Model { cancelAlert(): void { mobx.action(() => { this.alertMessage.set(null); - this.modalsModel.popModal(); })(); if (this.alertPromiseResolver != null) { this.alertPromiseResolver(false); @@ -478,7 +477,7 @@ class Model { if (this.alertMessage.get() != null) { if (checkKeyPressed(waveEvent, "Escape")) { e.preventDefault(); - this.cancelAlert(); + this.modalsModel.popModal(() => this.cancelAlert()); return; } if (checkKeyPressed(waveEvent, "Enter")) { @@ -488,6 +487,10 @@ class Model { } return; } + if (checkKeyPressed(waveEvent, "Escape") && this.modalsModel.store.length > 0) { + this.modalsModel.popModal(); + return; + } if (this.activeMainView.get() == "bookmarks") { this.bookmarksModel.handleDocKeyDown(e); } @@ -495,10 +498,10 @@ class Model { this.historyViewModel.handleDocKeyDown(e); } if (this.activeMainView.get() == "connections") { - this.historyViewModel.handleDocKeyDown(e); + this.connectionViewModel.handleDocKeyDown(e); } if (this.activeMainView.get() == "clientsettings") { - this.historyViewModel.handleDocKeyDown(e); + this.clientSettingsViewModel.handleDocKeyDown(e); } else { if (checkKeyPressed(waveEvent, "Escape")) { e.preventDefault(); @@ -506,9 +509,6 @@ class Model { this.showSessionView(); return; } - if (this.clearModals()) { - return; - } const inputModel = this.inputModel; inputModel.toggleInfoMsg(); if (inputModel.inputMode.get() != null) { @@ -628,33 +628,6 @@ class Model { return screen.getTermWrap(line.lineid); } - clearModals(): boolean { - let didSomething = false; - mobx.action(() => { - if (this.screenSettingsModal.get()) { - this.screenSettingsModal.set(null); - didSomething = true; - } - if (this.sessionSettingsModal.get()) { - this.sessionSettingsModal.set(null); - didSomething = true; - } - if (this.screenSettingsModal.get()) { - this.screenSettingsModal.set(null); - didSomething = true; - } - if (this.clientSettingsModal.get()) { - this.clientSettingsModal.set(false); - didSomething = true; - } - if (this.lineSettingsModal.get()) { - this.lineSettingsModal.set(null); - didSomething = true; - } - })(); - return didSomething; - } - restartWaveSrv(): void { getApi().restartWaveSrv(); }