From c1e1f3df24796375f3d7c1898db68b8a853ebde4 Mon Sep 17 00:00:00 2001 From: Abitofevrything <54505189+abitofevrything@users.noreply.github.com> Date: Sat, 9 Oct 2021 21:20:12 +0200 Subject: [PATCH] Add shortcut to reopen last closed tab, closes #2211 (#2214) --- src/public/app/services/tab_manager.js | 21 +++++++++++++++++++++ src/services/keyboard_actions.js | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 4ae14dc04..cfe025d8b 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -14,6 +14,8 @@ export default class TabManager extends Component { this.activeNtxId = null; + this.recentlyClosedTabs = []; + this.tabsUpdate = new SpacedUpdate(async () => { if (!appContext.isMainWindow) { return; @@ -303,6 +305,8 @@ export default class TabManager extends Component { await this.triggerEvent('beforeTabRemove', { ntxIds: ntxIdsToRemove }); + this.recentlyClosedTabs.push(noteContextToRemove); + if (!noteContextToRemove.isMainContext()) { await this.activateNoteContext(noteContextToRemove.getMainContext().ntxId); } @@ -410,6 +414,23 @@ export default class TabManager extends Component { this.triggerCommand('openInWindow', {notePath, hoistedNoteId}); } + async reopenLastTabCommand() { + if (this.recentlyClosedTabs.length > 0) { + const noteContext = this.recentlyClosedTabs.pop(); + + this.child(noteContext); + + await this.triggerEvent('newNoteContextCreated', {noteContext}); + + this.activateNoteContext(noteContext.ntxId); + + await this.triggerEvent('noteSwitched', { + noteContext: noteContext, + notePath: noteContext.notePath + }); + } + } + hoistedNoteChangedEvent() { this.tabsUpdate.scheduleUpdate(); } diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index cc8672672..c736e7bea 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -207,6 +207,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [ description: "Closes active tab", scope: "window" }, + { + actionName: "reopenLastTab", + defaultShortcuts: isElectron ? ["CommandOrControl+Shift+T"] : [], + description: "Repoens the last closed tab", + scope: "window" + }, { actionName: "activateNextTab", defaultShortcuts: isElectron ? ["CommandOrControl+Tab"] : [],