From ef5da75e5e1b5279d70f637ddd348519d3ddffbb Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Sat, 21 Sep 2024 17:25:09 +0200 Subject: [PATCH] Refactor ZenKeyboardShortcuts to add zenChangeWorkspaceBack shortcut --- src/ZenKeyboardShortcuts.mjs | 4 +++- src/ZenWorkspaces.mjs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ZenKeyboardShortcuts.mjs b/src/ZenKeyboardShortcuts.mjs index 7138be2..8fb5a11 100644 --- a/src/ZenKeyboardShortcuts.mjs +++ b/src/ZenKeyboardShortcuts.mjs @@ -10,6 +10,7 @@ const kZKSActions = { // Workspace actions zenChangeWorkspace: ['ZenWorkspaces.changeWorkspaceShortcut()', 'zen-change-workspace', 'workspace-action'], + zenChangeWorkspaceBack: ['ZenWorkspaces.changeWorkspaceShortcut(-1)', 'zen-change-workspace-back', 'workspace-action'], // manage actions openNewTab: ['command:cmd_newNavigatorTabNoEvent', 'open-new-tab', 'tab-action'], @@ -129,7 +130,8 @@ const kZenDefaultShortcuts = { zenSplitViewClose: 'Ctrl+Alt+U', // Workspace actions - zenChangeWorkspace: 'Ctrl+Shift+E', + zenChangeWorkspace: 'Ctrl+E', + zenChangeWorkspaceBack: 'Ctrl+Shift+E', // Compact mode actions zenToggleCompactMode: 'Ctrl+Alt+C', diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index e2f23ce..4952f57 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -775,12 +775,13 @@ var ZenWorkspaces = { await this.openEditDialog(this._contextMenuId); }, - async changeWorkspaceShortcut() { + async changeWorkspaceShortcut(offset = 1) { // Cycle through workspaces let workspaces = await this._workspaces(); let activeWorkspace = workspaces.workspaces.find((workspace) => workspace.used); let workspaceIndex = workspaces.workspaces.indexOf(activeWorkspace); - let nextWorkspace = workspaces.workspaces[workspaceIndex + 1] || workspaces.workspaces[0]; + // note: offset can be negative + let nextWorkspace = workspaces.workspaces[(workspaceIndex + offset + workspaces.workspaces.length) % workspaces.workspaces.length]; this.changeWorkspace(nextWorkspace); },