From aa1145960ab10949486af594db75eae75070be2a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 24 May 2021 18:08:31 +0100 Subject: [PATCH 1/3] Spaces keyboard shortcuts first cut --- src/i18n/strings/en_EN.json | 1 + src/vector/platform/ElectronPlatform.tsx | 45 +++++++++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 892ab66cad..358e2f951b 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -11,6 +11,7 @@ "Download Completed": "Download Completed", "Open": "Open", "Dismiss": "Dismiss", + "Switch to space by number": "Switch to space by number", "Open user settings": "Open user settings", "Previous/next recently visited room or community": "Previous/next recently visited room or community", "%(brand)s Desktop (%(platformName)s)": "%(brand)s Desktop (%(platformName)s)", diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 7ec8147edd..1afd84ee89 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -37,8 +37,8 @@ import {Room} from "matrix-js-sdk/src/models/room"; import Modal from "matrix-react-sdk/src/Modal"; import InfoDialog from "matrix-react-sdk/src/components/views/dialogs/InfoDialog"; import Spinner from "matrix-react-sdk/src/components/views/elements/Spinner"; -import {Categories, Modifiers, registerShortcut} from "matrix-react-sdk/src/accessibility/KeyboardShortcuts"; -import {Key} from "matrix-react-sdk/src/Keyboard"; +import {Categories, CMD_OR_CTRL, DIGITS, Modifiers, registerShortcut} from "matrix-react-sdk/src/accessibility/KeyboardShortcuts"; +import {isOnlyCtrlOrCmdKeyEvent, Key} from "matrix-react-sdk/src/Keyboard"; import React from "react"; import {randomString} from "matrix-js-sdk/src/randomstring"; import {Action} from "matrix-react-sdk/src/dispatcher/actions"; @@ -47,6 +47,8 @@ import {showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateTo import {CheckUpdatesPayload} from "matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload"; import ToastStore from "matrix-react-sdk/src/stores/ToastStore"; import GenericExpiringToast from "matrix-react-sdk/src/components/views/toasts/GenericExpiringToast"; +import SettingsStore from 'matrix-react-sdk/src/settings/SettingsStore'; +import SpaceStore from 'matrix-react-sdk/src/stores/SpaceStore'; const electron = window.electron; const isMac = navigator.platform.toUpperCase().includes('MAC'); @@ -270,6 +272,14 @@ export default class ElectronPlatform extends VectorBasePlatform { }); // register OS-specific shortcuts + registerShortcut(Categories.NAVIGATION, { + keybinds: [{ + modifiers: [CMD_OR_CTRL], + key: DIGITS, + }], + description: _td("Switch to space by number"), + }); + if (isMac) { registerShortcut(Categories.NAVIGATION, { keybinds: [{ @@ -545,9 +555,16 @@ export default class ElectronPlatform extends VectorBasePlatform { }); } - _navigateForwardBack(back: boolean) { + private navigateForwardBack(back: boolean) { this._ipcCall(back ? "navigateBack" : "navigateForward"); } + private navigateToSpace(num: number) { + if (num === 0) { + SpaceStore.instance.setActiveSpace(null); + } else if (SpaceStore.instance.spacePanelSpaces.length >= num) { + SpaceStore.instance.setActiveSpace(SpaceStore.instance.spacePanelSpaces[num - 1]); + } + } onKeyDown(ev: KeyboardEvent): boolean { let handled = false; @@ -556,7 +573,7 @@ export default class ElectronPlatform extends VectorBasePlatform { case Key.SQUARE_BRACKET_LEFT: case Key.SQUARE_BRACKET_RIGHT: if (isMac && ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey) { - this._navigateForwardBack(ev.key === Key.SQUARE_BRACKET_LEFT); + this.navigateForwardBack(ev.key === Key.SQUARE_BRACKET_LEFT); handled = true; } break; @@ -564,7 +581,25 @@ export default class ElectronPlatform extends VectorBasePlatform { case Key.ARROW_LEFT: case Key.ARROW_RIGHT: if (!isMac && ev.altKey && !ev.metaKey && !ev.ctrlKey && !ev.shiftKey) { - this._navigateForwardBack(ev.key === Key.ARROW_LEFT); + this.navigateForwardBack(ev.key === Key.ARROW_LEFT); + handled = true; + } + break; + + case "1": + case "2": + case "3": + case "4": + case "5": + case "6": + case "7": + case "8": + case "9": + case "0": + if (SettingsStore.getValue("feature_spaces") && isOnlyCtrlOrCmdKeyEvent(ev)) { + const keyNum = parseInt(ev.key, 10); + // map keyNum {1..0} to a {0..9} where key 1 is the home space + this.navigateToSpace((keyNum + 9) % 10); handled = true; } break; From f7ea7b948a2ddf7765cce0e2abfdafd900b9aa2e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 24 May 2021 18:23:04 +0100 Subject: [PATCH 2/3] Wire space switch shortcut via dispatcher to prevent app load explosion due to skinning --- src/vector/platform/ElectronPlatform.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 1afd84ee89..ae7b7f850a 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -37,18 +37,24 @@ import {Room} from "matrix-js-sdk/src/models/room"; import Modal from "matrix-react-sdk/src/Modal"; import InfoDialog from "matrix-react-sdk/src/components/views/dialogs/InfoDialog"; import Spinner from "matrix-react-sdk/src/components/views/elements/Spinner"; -import {Categories, CMD_OR_CTRL, DIGITS, Modifiers, registerShortcut} from "matrix-react-sdk/src/accessibility/KeyboardShortcuts"; +import { + Categories, + CMD_OR_CTRL, + DIGITS, + Modifiers, + registerShortcut, +} from "matrix-react-sdk/src/accessibility/KeyboardShortcuts"; import {isOnlyCtrlOrCmdKeyEvent, Key} from "matrix-react-sdk/src/Keyboard"; import React from "react"; import {randomString} from "matrix-js-sdk/src/randomstring"; import {Action} from "matrix-react-sdk/src/dispatcher/actions"; import {ActionPayload} from "matrix-react-sdk/src/dispatcher/payloads"; +import {SwitchSpacePayload} from "matrix-react-sdk/src/dispatcher/payloads/SwitchSpacePayload"; import {showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateToast"; import {CheckUpdatesPayload} from "matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload"; import ToastStore from "matrix-react-sdk/src/stores/ToastStore"; import GenericExpiringToast from "matrix-react-sdk/src/components/views/toasts/GenericExpiringToast"; import SettingsStore from 'matrix-react-sdk/src/settings/SettingsStore'; -import SpaceStore from 'matrix-react-sdk/src/stores/SpaceStore'; const electron = window.electron; const isMac = navigator.platform.toUpperCase().includes('MAC'); @@ -559,11 +565,10 @@ export default class ElectronPlatform extends VectorBasePlatform { this._ipcCall(back ? "navigateBack" : "navigateForward"); } private navigateToSpace(num: number) { - if (num === 0) { - SpaceStore.instance.setActiveSpace(null); - } else if (SpaceStore.instance.spacePanelSpaces.length >= num) { - SpaceStore.instance.setActiveSpace(SpaceStore.instance.spacePanelSpaces[num - 1]); - } + dis.dispatch({ + action: Action.SwitchSpace, + num, + }); } onKeyDown(ev: KeyboardEvent): boolean { From 9e4eebed261e6a4d446aa8af78d18853a16a0ecc Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 18 Jun 2021 08:24:36 +0100 Subject: [PATCH 3/3] Change spaces shortcut to have 1 = space 1, 0 = home --- src/vector/platform/ElectronPlatform.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index ae7b7f850a..073599200b 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -602,9 +602,7 @@ export default class ElectronPlatform extends VectorBasePlatform { case "9": case "0": if (SettingsStore.getValue("feature_spaces") && isOnlyCtrlOrCmdKeyEvent(ev)) { - const keyNum = parseInt(ev.key, 10); - // map keyNum {1..0} to a {0..9} where key 1 is the home space - this.navigateToSpace((keyNum + 9) % 10); + this.navigateToSpace(parseInt(ev.key, 10)); handled = true; } break;