hotkeys to move tabs around (fixes #2079)

This commit is contained in:
Eugene Pankov 2020-02-05 14:53:26 +03:00
parent 9ca091e592
commit 4a50c84cfe
6 changed files with 55 additions and 0 deletions

View File

@ -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()

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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',

View File

@ -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()