From 2c3d93608b145d73c60ed20662af8aac6a68d433 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 25 Mar 2020 22:18:24 +0100 Subject: [PATCH] hotkey to reopen last tab (fixes #2239) --- .../src/components/appRoot.component.ts | 3 +++ terminus-core/src/configDefaults.linux.yaml | 2 ++ terminus-core/src/configDefaults.macos.yaml | 2 ++ terminus-core/src/configDefaults.windows.yaml | 2 ++ terminus-core/src/hotkeys.ts | 4 +++ terminus-core/src/services/app.service.ts | 26 +++++++++++++++++++ 6 files changed, 39 insertions(+) diff --git a/terminus-core/src/components/appRoot.component.ts b/terminus-core/src/components/appRoot.component.ts index 9031ace2..2108d6bf 100644 --- a/terminus-core/src/components/appRoot.component.ts +++ b/terminus-core/src/components/appRoot.component.ts @@ -114,6 +114,9 @@ export class AppRootComponent { if (hotkey === 'move-tab-right') { this.app.moveSelectedTabRight() } + if (hotkey === 'reopen-tab') { + this.app.reopenLastTab() + } } if (hotkey === 'toggle-fullscreen') { this.hostApp.toggleFullscreen() diff --git a/terminus-core/src/configDefaults.linux.yaml b/terminus-core/src/configDefaults.linux.yaml index 12ebbe56..16bc634f 100644 --- a/terminus-core/src/configDefaults.linux.yaml +++ b/terminus-core/src/configDefaults.linux.yaml @@ -7,6 +7,8 @@ hotkeys: - 'F11' close-tab: - 'Ctrl-Shift-W' + reopen-tab: + - 'Ctrl-Shift-T' toggle-last-tab: [] rename-tab: - 'Ctrl-Shift-R' diff --git a/terminus-core/src/configDefaults.macos.yaml b/terminus-core/src/configDefaults.macos.yaml index a4ce567e..52b1d532 100644 --- a/terminus-core/src/configDefaults.macos.yaml +++ b/terminus-core/src/configDefaults.macos.yaml @@ -7,6 +7,8 @@ hotkeys: - 'Ctrl+⌘+F' close-tab: - '⌘-W' + reopen-tab: + - '⌘-Shift-T' toggle-last-tab: [] rename-tab: - '⌘-R' diff --git a/terminus-core/src/configDefaults.windows.yaml b/terminus-core/src/configDefaults.windows.yaml index 962f70e8..7d81c5c7 100644 --- a/terminus-core/src/configDefaults.windows.yaml +++ b/terminus-core/src/configDefaults.windows.yaml @@ -8,6 +8,8 @@ hotkeys: - 'Alt-Enter' close-tab: - 'Ctrl-Shift-W' + reopen-tab: + - 'Ctrl-Shift-T' toggle-last-tab: [] rename-tab: - 'Ctrl-Shift-R' diff --git a/terminus-core/src/hotkeys.ts b/terminus-core/src/hotkeys.ts index 914ee262..352abe05 100644 --- a/terminus-core/src/hotkeys.ts +++ b/terminus-core/src/hotkeys.ts @@ -25,6 +25,10 @@ export class AppHotkeyProvider extends HotkeyProvider { id: 'close-tab', name: 'Close tab', }, + { + id: 'reopen-tab', + name: 'Reopen last tab', + }, { id: 'toggle-last-tab', name: 'Toggle last tab', diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 52c0848e..75f92912 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -8,6 +8,7 @@ import { BaseTabComponent } from '../components/baseTab.component' import { SplitTabComponent } from '../components/splitTab.component' import { SelectorModalComponent } from '../components/selectorModal.component' import { SelectorOption } from '../api/selector' +import { RecoveryToken } from '../api/tabRecovery' import { ConfigService } from './config.service' import { HostAppService } from './hostApp.service' @@ -49,6 +50,7 @@ export class AppService { private lastTabIndex = 0 private _activeTab: BaseTabComponent + private closedTabsStack: RecoveryToken[] = [] private activeTabChange = new Subject() private tabsChanged = new Subject() @@ -98,6 +100,13 @@ export class AppService { hostApp.windowFocused$.subscribe(() => { this._activeTab?.emitFocused() }) + + this.tabClosed$.subscribe(async tab => { + const token = await tab.getRecoveryToken() + if (token) { + this.closedTabsStack.push(token) + } + }) } addTabRaw (tab: BaseTabComponent, index: number|null = null): void { @@ -161,6 +170,23 @@ export class AppService { return tab } + async reopenLastTab (): Promise { + const token = this.closedTabsStack.pop() + if (token) { + const recoveredTab = await this.tabRecovery.recoverTab(token) + if (recoveredTab) { + const tab = this.tabsService.create(recoveredTab.type, recoveredTab.options) + if (this.activeTab) { + this.addTabRaw(tab, this.tabs.indexOf(this.activeTab) + 1) + } else { + this.addTabRaw(tab) + } + return tab + } + } + return null + } + selectTab (tab: BaseTabComponent): void { if (this._activeTab === tab) { this._activeTab.emitFocused()