From d3b9e08446708654b3c6fad565b734d93effe683 Mon Sep 17 00:00:00 2001 From: Giulio Ganci Date: Fri, 3 Jun 2022 18:56:19 +0200 Subject: [PATCH] feat: hotkeys to navigate forward or backward between tabs --- src/renderer/components/Workspace.vue | 24 ++++++++++++++++++++++-- src/renderer/stores/workspaces.js | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/Workspace.vue b/src/renderer/components/Workspace.vue index fec4a3db..fe8ac2f6 100644 --- a/src/renderer/components/Workspace.vue +++ b/src/renderer/components/Workspace.vue @@ -556,7 +556,9 @@ export default { selectTab, newTab, removeTab, - updateTabs + updateTabs, + selectNextTab, + selectPrevTab } = workspacesStore; return { @@ -568,7 +570,9 @@ export default { selectTab, newTab, removeTab, - updateTabs + updateTabs, + selectNextTab, + selectPrevTab }; }, data () { @@ -670,6 +674,22 @@ export default { if (currentTab) this.closeTab(currentTab); } + + // select next tab + if (e.altKey && (e.ctrlKey || e.metaKey) && e.key === 'ArrowRight') + this.selectNextTab({ uid: this.connection.uid }); + + // select prev tab + if (e.altKey && (e.ctrlKey || e.metaKey) && e.key === 'ArrowLeft') + this.selectPrevTab({ uid: this.connection.uid }); + + // select tab by index (range 1-9). CTRL|CMD number + if ((e.ctrlKey || e.metaKey) && !e.altKey && e.keyCode >= 49 && e.keyCode <= 57) { + const newIndex = parseInt(e.key) - 1; + + if (this.workspace.tabs[newIndex]) + this.selectTab({ uid: this.connection.uid, tab: this.workspace.tabs[newIndex].uid }); + } }, openAsPermanentTab (tab) { const permanentTabs = { diff --git a/src/renderer/stores/workspaces.js b/src/renderer/stores/workspaces.js index d3464f98..d1381fae 100644 --- a/src/renderer/stores/workspaces.js +++ b/src/renderer/stores/workspaces.js @@ -609,6 +609,26 @@ export const useWorkspacesStore = defineStore('workspaces', { : workspace ); }, + selectNextTab ({ uid }) { + const workspace = this.workspaces.find(workspace => workspace.uid === uid); + + let newIndex = workspace.tabs.findIndex(tab => tab.selected || tab.uid === workspace.selectedTab) + 1; + + if (newIndex > workspace.tabs.length -1) + newIndex = 0; + + this.selectTab({ uid, tab: workspace.tabs[newIndex].uid }); + }, + selectPrevTab ({ uid }) { + const workspace = this.workspaces.find(workspace => workspace.uid === uid); + + let newIndex = workspace.tabs.findIndex(tab => tab.selected || tab.uid === workspace.selectedTab) - 1; + + if (newIndex < 0) + newIndex = workspace.tabs.length -1; + + this.selectTab({ uid, tab: workspace.tabs[newIndex].uid }); + }, updateTabs ({ uid, tabs }) { this.workspaces = this.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, tabs }