Przeglądaj źródła

hotkeys to move tabs around (fixes #2079)

Eugene Pankov 5 lat temu
rodzic
commit
4a50c84cfe

+ 6 - 0
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()

+ 4 - 0
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:

+ 4 - 0
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:

+ 4 - 0
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:

+ 8 - 0
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',

+ 29 - 0
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()