Merge pull request #17457 from vector-im/t3chguy/fix/17128-1

This commit is contained in:
Michael Telatynski 2021-06-22 14:21:46 +01:00 committed by GitHub
commit 1805a28d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 5 deletions

View File

@ -11,6 +11,7 @@
"Download Completed": "Download Completed", "Download Completed": "Download Completed",
"Open": "Open", "Open": "Open",
"Dismiss": "Dismiss", "Dismiss": "Dismiss",
"Switch to space by number": "Switch to space by number",
"Open user settings": "Open user settings", "Open user settings": "Open user settings",
"Previous/next recently visited room or community": "Previous/next recently visited room or community", "Previous/next recently visited room or community": "Previous/next recently visited room or community",
"%(brand)s Desktop (%(platformName)s)": "%(brand)s Desktop (%(platformName)s)", "%(brand)s Desktop (%(platformName)s)": "%(brand)s Desktop (%(platformName)s)",

View File

@ -37,16 +37,24 @@ import {Room} from "matrix-js-sdk/src/models/room";
import Modal from "matrix-react-sdk/src/Modal"; import Modal from "matrix-react-sdk/src/Modal";
import InfoDialog from "matrix-react-sdk/src/components/views/dialogs/InfoDialog"; import InfoDialog from "matrix-react-sdk/src/components/views/dialogs/InfoDialog";
import Spinner from "matrix-react-sdk/src/components/views/elements/Spinner"; import Spinner from "matrix-react-sdk/src/components/views/elements/Spinner";
import {Categories, Modifiers, registerShortcut} from "matrix-react-sdk/src/accessibility/KeyboardShortcuts"; import {
import {Key} from "matrix-react-sdk/src/Keyboard"; 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 React from "react";
import {randomString} from "matrix-js-sdk/src/randomstring"; import {randomString} from "matrix-js-sdk/src/randomstring";
import {Action} from "matrix-react-sdk/src/dispatcher/actions"; import {Action} from "matrix-react-sdk/src/dispatcher/actions";
import {ActionPayload} from "matrix-react-sdk/src/dispatcher/payloads"; 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 {showToast as showUpdateToast} from "matrix-react-sdk/src/toasts/UpdateToast";
import {CheckUpdatesPayload} from "matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload"; import {CheckUpdatesPayload} from "matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload";
import ToastStore from "matrix-react-sdk/src/stores/ToastStore"; import ToastStore from "matrix-react-sdk/src/stores/ToastStore";
import GenericExpiringToast from "matrix-react-sdk/src/components/views/toasts/GenericExpiringToast"; import GenericExpiringToast from "matrix-react-sdk/src/components/views/toasts/GenericExpiringToast";
import SettingsStore from 'matrix-react-sdk/src/settings/SettingsStore';
const electron = window.electron; const electron = window.electron;
const isMac = navigator.platform.toUpperCase().includes('MAC'); const isMac = navigator.platform.toUpperCase().includes('MAC');
@ -270,6 +278,14 @@ export default class ElectronPlatform extends VectorBasePlatform {
}); });
// register OS-specific shortcuts // register OS-specific shortcuts
registerShortcut(Categories.NAVIGATION, {
keybinds: [{
modifiers: [CMD_OR_CTRL],
key: DIGITS,
}],
description: _td("Switch to space by number"),
});
if (isMac) { if (isMac) {
registerShortcut(Categories.NAVIGATION, { registerShortcut(Categories.NAVIGATION, {
keybinds: [{ keybinds: [{
@ -545,9 +561,15 @@ export default class ElectronPlatform extends VectorBasePlatform {
}); });
} }
_navigateForwardBack(back: boolean) { private navigateForwardBack(back: boolean) {
this._ipcCall(back ? "navigateBack" : "navigateForward"); this._ipcCall(back ? "navigateBack" : "navigateForward");
} }
private navigateToSpace(num: number) {
dis.dispatch<SwitchSpacePayload>({
action: Action.SwitchSpace,
num,
});
}
onKeyDown(ev: KeyboardEvent): boolean { onKeyDown(ev: KeyboardEvent): boolean {
let handled = false; let handled = false;
@ -556,7 +578,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
case Key.SQUARE_BRACKET_LEFT: case Key.SQUARE_BRACKET_LEFT:
case Key.SQUARE_BRACKET_RIGHT: case Key.SQUARE_BRACKET_RIGHT:
if (isMac && ev.metaKey && !ev.altKey && !ev.ctrlKey && !ev.shiftKey) { 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; handled = true;
} }
break; break;
@ -564,7 +586,23 @@ export default class ElectronPlatform extends VectorBasePlatform {
case Key.ARROW_LEFT: case Key.ARROW_LEFT:
case Key.ARROW_RIGHT: case Key.ARROW_RIGHT:
if (!isMac && ev.altKey && !ev.metaKey && !ev.ctrlKey && !ev.shiftKey) { 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)) {
this.navigateToSpace(parseInt(ev.key, 10));
handled = true; handled = true;
} }
break; break;