From 4a50c84cfee86273d5e512e4e4bdfc115e71e4b1 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 5 Feb 2020 14:53:26 +0300 Subject: [PATCH] hotkeys to move tabs around (fixes #2079) --- .../src/components/appRoot.component.ts | 6 ++++ terminus-core/src/configDefaults.linux.yaml | 4 +++ terminus-core/src/configDefaults.macos.yaml | 4 +++ terminus-core/src/configDefaults.windows.yaml | 4 +++ terminus-core/src/hotkeys.ts | 8 +++++ terminus-core/src/services/app.service.ts | 29 +++++++++++++++++++ 6 files changed, 55 insertions(+) diff --git a/terminus-core/src/components/appRoot.component.ts b/terminus-core/src/components/appRoot.component.ts index a78e0a71..54a88da9 100644 --- a/terminus-core/src/components/appRoot.component.ts +++ b/terminus-core/src/components/appRoot.component.ts @@ -107,6 +107,12 @@ export class AppRootComponent { if (hotkey === 'previous-tab') { this.app.previousTab() } + if (hotkey === 'move-tab-left') { + this.app.moveSelectedTabLeft() + } + if (hotkey === 'move-tab-right') { + this.app.moveSelectedTabRight() + } } if (hotkey === 'toggle-fullscreen') { this.hostApp.toggleFullscreen() diff --git a/terminus-core/src/configDefaults.linux.yaml b/terminus-core/src/configDefaults.linux.yaml index 4918e081..12ebbe56 100644 --- a/terminus-core/src/configDefaults.linux.yaml +++ b/terminus-core/src/configDefaults.linux.yaml @@ -16,6 +16,10 @@ hotkeys: previous-tab: - 'Ctrl-Shift-Left' - 'Ctrl-Shift-Tab' + move-tab-left: + - 'Ctrl-Shift-PageUp' + move-tab-right: + - 'Ctrl-Shift-PageDown' tab-1: - 'Alt-1' tab-2: diff --git a/terminus-core/src/configDefaults.macos.yaml b/terminus-core/src/configDefaults.macos.yaml index bbb02c7c..a4ce567e 100644 --- a/terminus-core/src/configDefaults.macos.yaml +++ b/terminus-core/src/configDefaults.macos.yaml @@ -14,6 +14,10 @@ hotkeys: - 'Ctrl-Tab' previous-tab: - 'Ctrl-Shift-Tab' + move-tab-left: + - '⌘-Shift-Left' + move-tab-right: + - '⌘-Shift-Right' tab-1: - '⌘-1' tab-2: diff --git a/terminus-core/src/configDefaults.windows.yaml b/terminus-core/src/configDefaults.windows.yaml index 0360f696..962f70e8 100644 --- a/terminus-core/src/configDefaults.windows.yaml +++ b/terminus-core/src/configDefaults.windows.yaml @@ -17,6 +17,10 @@ hotkeys: previous-tab: - 'Ctrl-Shift-Left' - 'Ctrl-Shift-Tab' + move-tab-left: + - 'Ctrl-Shift-PageUp' + move-tab-right: + - 'Ctrl-Shift-PageDown' tab-1: - 'Alt-1' tab-2: diff --git a/terminus-core/src/hotkeys.ts b/terminus-core/src/hotkeys.ts index 2d2c6e06..914ee262 100644 --- a/terminus-core/src/hotkeys.ts +++ b/terminus-core/src/hotkeys.ts @@ -37,6 +37,14 @@ export class AppHotkeyProvider extends HotkeyProvider { id: 'previous-tab', name: 'Previous tab', }, + { + id: 'move-tab-left', + name: 'Move tab to the left', + }, + { + id: 'move-tab-right', + name: 'Move tab to the right', + }, { id: 'tab-1', name: 'Tab 1', diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 2756296c..683a03d1 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -224,6 +224,35 @@ export class AppService { } } + moveSelectedTabLeft () { + if (this.tabs.length > 1) { + const tabIndex = this.tabs.indexOf(this._activeTab) + if (tabIndex > 0) { + this.swapTabs(this._activeTab, this.tabs[tabIndex - 1]) + } else if (this.config.store.appearance.cycleTabs) { + this.swapTabs(this._activeTab, this.tabs[this.tabs.length - 1]) + } + } + } + + moveSelectedTabRight () { + if (this.tabs.length > 1) { + const tabIndex = this.tabs.indexOf(this._activeTab) + if (tabIndex < this.tabs.length - 1) { + this.swapTabs(this._activeTab, this.tabs[tabIndex + 1]) + } else if (this.config.store.appearance.cycleTabs) { + this.swapTabs(this._activeTab, this.tabs[0]) + } + } + } + + swapTabs (a: BaseTabComponent, b: BaseTabComponent) { + const i1 = this.tabs.indexOf(a) + const i2 = this.tabs.indexOf(b) + this.tabs[i1] = b + this.tabs[i2] = a + } + /** @hidden */ emitTabsChanged () { this.tabsChanged.next()