From 7eb26ba088f16b155c85232cb22c02ff09e115a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 19:28:03 +0100 Subject: [PATCH 01/10] Move filter rooms to navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/accessibility/KeyboardShortcuts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accessibility/KeyboardShortcuts.ts b/src/accessibility/KeyboardShortcuts.ts index 4c7b73d5d2a..8b3242485f1 100644 --- a/src/accessibility/KeyboardShortcuts.ts +++ b/src/accessibility/KeyboardShortcuts.ts @@ -96,7 +96,6 @@ export const CATEGORIES: Record = { }, [CategoryName.ROOM_LIST]: { categoryLabel: _td("Room List"), settingNames: [ - "KeyBinding.filterRooms", "KeyBinding.selectRoomInRoomList", "KeyBinding.collapseSectionInRoomList", "KeyBinding.expandSectionInRoomList", @@ -118,6 +117,7 @@ export const CATEGORIES: Record = { "KeyBinding.nextRoom", "KeyBinding.previousRoom", "KeyBinding.toggleSpacePanel", + "KeyBinding.filterRooms", ], }, [CategoryName.AUTOCOMPLETE]: { categoryLabel: _td("Autocomplete"), From 31f497ca495e7e2f756d7055c993f01d503594bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 19:29:09 +0100 Subject: [PATCH 02/10] Add missing jump to message shortcuts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/accessibility/KeyboardShortcuts.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/accessibility/KeyboardShortcuts.ts b/src/accessibility/KeyboardShortcuts.ts index 8b3242485f1..4613da4a956 100644 --- a/src/accessibility/KeyboardShortcuts.ts +++ b/src/accessibility/KeyboardShortcuts.ts @@ -92,6 +92,8 @@ export const CATEGORIES: Record = { "KeyBinding.searchInRoom", "KeyBinding.scrollUpInTimeline", "KeyBinding.scrollDownInTimeline", + "KeyBinding.jumpToFirstMessageInTimeline", + "KeyBinding.jumpToLastMessageInTimeline", ], }, [CategoryName.ROOM_LIST]: { categoryLabel: _td("Room List"), @@ -417,6 +419,20 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = { }, displayName: _td("Toggle hidden event visibility"), }, + "KeyBinding.jumpToFirstMessageInTimeline": { + default: { + key: Key.HOME, + ctrlKey: true, + }, + displayName: _td("Jump to first message"), + }, + "KeyBinding.jumpToLastMessageInTimeline": { + default: { + key: Key.END, + ctrlKey: true, + }, + displayName: _td("Jump to last message"), + }, }; export const registerShortcut = (shortcutName: string, categoryName: CategoryName, shortcut: ISetting): void => { From 0b757ca5f63b6561194c996369262c1989a7ddd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 19:38:41 +0100 Subject: [PATCH 03/10] Add `getKeyboardShortcutValue` and `getKeyboardShortcutDisplayName` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../settings/tabs/user/KeyboardUserSettingsTab.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx b/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx index 2950bd77624..9f17bd147c0 100644 --- a/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx @@ -29,6 +29,15 @@ import SdkConfig from "../../../../../SdkConfig"; import { isMac, Key } from "../../../../../Keyboard"; import { _t } from "../../../../../languageHandler"; +// TODO: This should return KeyCombo but it has ctrlOrCmd instead of ctrlOrCmdKey +const getKeyboardShortcutValue = (name: string) => { + return KEYBOARD_SHORTCUTS[name]?.default; +}; + +const getKeyboardShortcutDisplayName = (name: string): string => { + return KEYBOARD_SHORTCUTS[name]?.displayName as string; +}; + interface IKeyboardKeyProps { name: string; last?: boolean; @@ -49,7 +58,7 @@ interface IKeyboardShortcutProps { } export const KeyboardShortcut: React.FC = ({ name }) => { - const value = KEYBOARD_SHORTCUTS[name]?.default; + const value = getKeyboardShortcutValue(name); if (!value) return null; const modifiersElement = []; @@ -83,7 +92,7 @@ const visibleCategories = Object.entries(CATEGORIES).filter(([categoryName]) => const KeyboardShortcutRow: React.FC = ({ name }) => { return
- { KEYBOARD_SHORTCUTS[name].displayName } + { getKeyboardShortcutDisplayName(name) }
; }; From 2993bdb9167a2e2fe88a5fb29db6ec1ac8835c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 19:45:45 +0100 Subject: [PATCH 04/10] Add `getKeyboardShortcuts` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/accessibility/KeyboardShortcuts.ts | 10 +++++++++- .../settings/tabs/user/KeyboardUserSettingsTab.tsx | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/accessibility/KeyboardShortcuts.ts b/src/accessibility/KeyboardShortcuts.ts index 4613da4a956..fb6381b435c 100644 --- a/src/accessibility/KeyboardShortcuts.ts +++ b/src/accessibility/KeyboardShortcuts.ts @@ -19,6 +19,10 @@ import { _td } from "../languageHandler"; import { isMac, Key } from "../Keyboard"; import { ISetting } from "../settings/Settings"; +interface IKeyboardShortcuts { + [setting: string]: ISetting; +} + export interface ICategory { categoryLabel: string; settingNames: string[]; @@ -139,7 +143,7 @@ export const CATEGORIES: Record = { // This is very intentionally modelled after SETTINGS as it will make it easier // to implement customizable keyboard shortcuts // TODO: TravisR will fix this nightmare when the new version of the SettingsStore becomes a thing -export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = { +const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { "KeyBinding.toggleBoldInComposer": { default: { ctrlOrCmdKey: true, @@ -435,6 +439,10 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = { }, }; +export const getKeyboardShortcuts = (): IKeyboardShortcuts => { + return KEYBOARD_SHORTCUTS; +}; + export const registerShortcut = (shortcutName: string, categoryName: CategoryName, shortcut: ISetting): void => { KEYBOARD_SHORTCUTS[shortcutName] = shortcut; CATEGORIES[categoryName].settingNames.push(shortcutName); diff --git a/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx b/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx index 9f17bd147c0..29a4060a9c5 100644 --- a/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx @@ -18,7 +18,7 @@ limitations under the License. import React from "react"; import { - KEYBOARD_SHORTCUTS, + getKeyboardShortcuts, ALTERNATE_KEY_NAME, KEY_ICON, ICategory, @@ -31,11 +31,11 @@ import { _t } from "../../../../../languageHandler"; // TODO: This should return KeyCombo but it has ctrlOrCmd instead of ctrlOrCmdKey const getKeyboardShortcutValue = (name: string) => { - return KEYBOARD_SHORTCUTS[name]?.default; + return getKeyboardShortcuts()[name]?.default; }; const getKeyboardShortcutDisplayName = (name: string): string => { - return KEYBOARD_SHORTCUTS[name]?.displayName as string; + return getKeyboardShortcuts()[name]?.displayName as string; }; interface IKeyboardKeyProps { From b32828b68169aa125c74af91f262d221e4bb3322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 20:07:40 +0100 Subject: [PATCH 05/10] Add missing keyboard shortcuts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/accessibility/KeyboardShortcuts.ts | 61 ++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/accessibility/KeyboardShortcuts.ts b/src/accessibility/KeyboardShortcuts.ts index fb6381b435c..a668a662866 100644 --- a/src/accessibility/KeyboardShortcuts.ts +++ b/src/accessibility/KeyboardShortcuts.ts @@ -18,6 +18,7 @@ limitations under the License. import { _td } from "../languageHandler"; import { isMac, Key } from "../Keyboard"; import { ISetting } from "../settings/Settings"; +import SettingsStore from "../settings/SettingsStore"; interface IKeyboardShortcuts { [setting: string]: ISetting; @@ -69,6 +70,7 @@ export const CATEGORIES: Record = { [CategoryName.COMPOSER]: { categoryLabel: _td("Composer"), settingNames: [ + "KeyBinding.sendMessageInComposer", "KeyBinding.toggleBoldInComposer", "KeyBinding.toggleItalicsInComposer", "KeyBinding.toggleQuoteInComposer", @@ -80,6 +82,8 @@ export const CATEGORIES: Record = { "KeyBinding.jumpToEndInComposer", "KeyBinding.nextMessageInComposerHistory", "KeyBinding.previousMessageInComposerHistory", + "KeyBinding.editUndoInComposer", + "KeyBinding.editRedoInComposer", ], }, [CategoryName.CALLS]: { categoryLabel: _td("Calls"), @@ -131,6 +135,8 @@ export const CATEGORIES: Record = { "KeyBinding.cancelAutoComplete", "KeyBinding.nextOptionInAutoComplete", "KeyBinding.previousOptionInAutoComplete", + "KeyBinding.completeAutocomplete", + "KeyBinding.forceCompleteAutocomplete", ], }, [CategoryName.LABS]: { categoryLabel: _td("Labs"), @@ -165,13 +171,6 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Toggle Quote"), }, - "KeyBinding.newLineInComposer": { - default: { - shiftKey: true, - key: Key.ENTER, - }, - displayName: _td("New line"), - }, "KeyBinding.cancelReplyInComposer": { default: { key: Key.ESCAPE, @@ -437,10 +436,56 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Jump to last message"), }, + "KeyBinding.editUndoInComposer": { + default: { + key: Key.Z, + ctrlOrCmdKey: true, + }, + displayName: _td("Undo edit"), + }, + "KeyBinding.completeAutocomplete": { + default: { + key: Key.ENTER, + }, + displayName: _td("Complete"), + }, + "KeyBinding.forceCompleteAutocomplete": { + default: { + key: Key.TAB, + }, + displayName: _td("Force complete"), + }, }; export const getKeyboardShortcuts = (): IKeyboardShortcuts => { - return KEYBOARD_SHORTCUTS; + const keyboardShortcuts = KEYBOARD_SHORTCUTS; + const ctrlEnterToSend = SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend'); + + keyboardShortcuts["KeyBinding.sendMessageInComposer"] = { + default: { + key: Key.ENTER, + ctrlOrCmdKey: ctrlEnterToSend, + }, + displayName: _td("Send message"), + + }; + keyboardShortcuts["KeyBinding.newLineInComposer"] = { + default: { + key: Key.ENTER, + shiftKey: !ctrlEnterToSend, + }, + displayName: _td("New line"), + }; + keyboardShortcuts["KeyBinding.editRedoInComposer"] = { + default: { + key: isMac ? Key.Z : Key.Y, + ctrlOrCmdKey: true, + shiftKey: isMac, + }, + displayName: _td("Redo edit"), + }; + + return keyboardShortcuts; }; export const registerShortcut = (shortcutName: string, categoryName: CategoryName, shortcut: ISetting): void => { From d393a32c1278d4f2ca8427f76a5f839934ec6d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 20:21:07 +0100 Subject: [PATCH 06/10] Change string enums to match `KeyboardShortcuts` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/KeyBindingsManager.ts | 88 +++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/KeyBindingsManager.ts b/src/KeyBindingsManager.ts index 37142baedd2..7f0a15b53e0 100644 --- a/src/KeyBindingsManager.ts +++ b/src/KeyBindingsManager.ts @@ -20,115 +20,115 @@ import { isMac } from './Keyboard'; /** Actions for the chat message composer component */ export enum MessageComposerAction { /** Send a message */ - Send = 'Send', + Send = 'KeyBinding.sendMessageInComposer', /** Go backwards through the send history and use the message in composer view */ - SelectPrevSendHistory = 'SelectPrevSendHistory', + SelectPrevSendHistory = 'KeyBinding.previousMessageInComposerHistory', /** Go forwards through the send history */ - SelectNextSendHistory = 'SelectNextSendHistory', + SelectNextSendHistory = 'KeyBinding.nextMessageInComposerHistory', /** Start editing the user's last sent message */ - EditPrevMessage = 'EditPrevMessage', + EditPrevMessage = 'KeyBinding.editPreviousMessage', /** Start editing the user's next sent message */ - EditNextMessage = 'EditNextMessage', + EditNextMessage = 'KeyBinding.editNextMessage', /** Cancel editing a message or cancel replying to a message */ - CancelEditing = 'CancelEditing', + CancelEditing = 'KeyBinding.cancelReplyInComposer', /** Set bold format the current selection */ - FormatBold = 'FormatBold', + FormatBold = 'KeyBinding.toggleBoldInComposer', /** Set italics format the current selection */ - FormatItalics = 'FormatItalics', + FormatItalics = 'KeyBinding.toggleItalicsInComposer', /** Format the current selection as quote */ - FormatQuote = 'FormatQuote', + FormatQuote = 'KeyBinding.toggleQuoteInComposer', /** Undo the last editing */ - EditUndo = 'EditUndo', + EditUndo = 'KeyBinding.editUndoInComposer', /** Redo editing */ - EditRedo = 'EditRedo', + EditRedo = 'KeyBinding.editRedoInComposer', /** Insert new line */ - NewLine = 'NewLine', + NewLine = 'KeyBinding.newLineInComposer', /** Move the cursor to the start of the message */ - MoveCursorToStart = 'MoveCursorToStart', + MoveCursorToStart = 'KeyBinding.jumpToStartInComposer', /** Move the cursor to the end of the message */ - MoveCursorToEnd = 'MoveCursorToEnd', + MoveCursorToEnd = 'KeyBinding.jumpToEndInComposer', } /** Actions for text editing autocompletion */ export enum AutocompleteAction { /** Accepts chosen autocomplete selection */ - Complete = 'Complete', + Complete = 'KeyBinding.completeAutocomplete', /** Accepts chosen autocomplete selection or, * if the autocompletion window is not shown, open the window and select the first selection */ - ForceComplete = 'ForceComplete', + ForceComplete = 'KeyBinding.forceCompleteAutocomplete', /** Move to the previous autocomplete selection */ - PrevSelection = 'PrevSelection', + PrevSelection = 'KeyBinding.previousOptionInAutoComplete', /** Move to the next autocomplete selection */ - NextSelection = 'NextSelection', + NextSelection = 'KeyBinding.nextOptionInAutoComplete', /** Close the autocompletion window */ - Cancel = 'Cancel', + Cancel = 'KeyBinding.cancelAutoComplete', } /** Actions for the room list sidebar */ export enum RoomListAction { /** Clear room list filter field */ - ClearSearch = 'ClearSearch', + ClearSearch = 'KeyBinding.clearRoomFilter', /** Navigate up/down in the room list */ - PrevRoom = 'PrevRoom', + PrevRoom = 'KeyBinding.downerRoom', /** Navigate down in the room list */ - NextRoom = 'NextRoom', + NextRoom = 'KeyBinding.upperRoom', /** Select room from the room list */ - SelectRoom = 'SelectRoom', + SelectRoom = 'KeyBinding.selectRoomInRoomList', /** Collapse room list section */ - CollapseSection = 'CollapseSection', + CollapseSection = 'KeyBinding.collapseSectionInRoomList', /** Expand room list section, if already expanded, jump to first room in the selection */ - ExpandSection = 'ExpandSection', + ExpandSection = 'KeyBinding.expandSectionInRoomList', } /** Actions for the current room view */ export enum RoomAction { /** Scroll up in the timeline */ - ScrollUp = 'ScrollUp', + ScrollUp = 'KeyBinding.scrollUpInTimeline', /** Scroll down in the timeline */ - RoomScrollDown = 'RoomScrollDown', + RoomScrollDown = 'KeyBinding.scrollDownInTimeline', /** Dismiss read marker and jump to bottom */ - DismissReadMarker = 'DismissReadMarker', + DismissReadMarker = 'KeyBinding.dismissReadMarkerAndJumpToBottom', /** Jump to oldest unread message */ - JumpToOldestUnread = 'JumpToOldestUnread', + JumpToOldestUnread = 'KeyBinding.jumpToOldestUnreadMessage', /** Upload a file */ - UploadFile = 'UploadFile', + UploadFile = 'KeyBinding.uploadFileToRoom', /** Focus search message in a room (must be enabled) */ - FocusSearch = 'FocusSearch', + FocusSearch = 'KeyBinding.searchInRoom', /** Jump to the first (downloaded) message in the room */ - JumpToFirstMessage = 'JumpToFirstMessage', + JumpToFirstMessage = 'KeyBinding.jumpToFirstMessageInTimeline', /** Jump to the latest message in the room */ - JumpToLatestMessage = 'JumpToLatestMessage', + JumpToLatestMessage = 'KeyBinding.jumpToLastMessageInTimeline', } /** Actions for navigating do various menus, dialogs or screens */ export enum NavigationAction { /** Jump to room search (search for a room) */ - FocusRoomSearch = 'FocusRoomSearch', + FocusRoomSearch = 'KeyBinding.filterRooms', /** Toggle the space panel */ - ToggleSpacePanel = 'ToggleSpacePanel', + ToggleSpacePanel = 'KeyBinding.toggleSpacePanel', /** Toggle the room side panel */ - ToggleRoomSidePanel = 'ToggleRoomSidePanel', + ToggleRoomSidePanel = 'KeyBinding.toggleRightPanel', /** Toggle the user menu */ - ToggleUserMenu = 'ToggleUserMenu', + ToggleUserMenu = 'KeyBinding.toggleTopLeftMenu', /** Toggle the short cut help dialog */ - OpenShortCutDialog = 'OpenShortCutDialog', + OpenShortCutDialog = 'KeyBinding.showKeyBindingsSettings', /** Got to the Element home screen */ - GoToHome = 'GoToHome', + GoToHome = 'KeyBinding.goToHomeView', /** Select prev room */ - SelectPrevRoom = 'SelectPrevRoom', + SelectPrevRoom = 'KeyBinding.previousRoom', /** Select next room */ - SelectNextRoom = 'SelectNextRoom', + SelectNextRoom = 'KeyBinding.nextRoom', /** Select prev room with unread messages */ - SelectPrevUnreadRoom = 'SelectPrevUnreadRoom', + SelectPrevUnreadRoom = 'KeyBinding.previousUnreadRoom', /** Select next room with unread messages */ - SelectNextUnreadRoom = 'SelectNextUnreadRoom', + SelectNextUnreadRoom = 'KeyBinding.nextUnreadRoom', } /** Actions only available when labs are enabled */ export enum LabsAction { /** Toggle visibility of hidden events */ - ToggleHiddenEventVisibility = 'ToggleHiddenEventVisibility', + ToggleHiddenEventVisibility = 'KeyBinding.toggleHiddenEventVisibility', } /** From c7bfb36f68ad270f3c7b9c3ded68d6eae9501eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 20:21:22 +0100 Subject: [PATCH 07/10] Export KeyBindingAction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/KeyBindingsManager.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/KeyBindingsManager.ts b/src/KeyBindingsManager.ts index 7f0a15b53e0..48968e31219 100644 --- a/src/KeyBindingsManager.ts +++ b/src/KeyBindingsManager.ts @@ -131,6 +131,10 @@ export enum LabsAction { ToggleHiddenEventVisibility = 'KeyBinding.toggleHiddenEventVisibility', } +export type KeyBindingAction = ( + MessageComposerAction | AutocompleteAction | RoomListAction | RoomAction | NavigationAction | LabsAction +); + /** * Represent a key combination. * From 9218b2f539f663dd2e57f226ddefa34ca879e57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 20:54:28 +0100 Subject: [PATCH 08/10] Use `KeyBindingAction`s in `KeybaordShortcuts` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/accessibility/KeyboardShortcuts.ts | 195 +++++++++++++------------ 1 file changed, 103 insertions(+), 92 deletions(-) diff --git a/src/accessibility/KeyboardShortcuts.ts b/src/accessibility/KeyboardShortcuts.ts index a668a662866..51bba7c02d6 100644 --- a/src/accessibility/KeyboardShortcuts.ts +++ b/src/accessibility/KeyboardShortcuts.ts @@ -19,14 +19,25 @@ import { _td } from "../languageHandler"; import { isMac, Key } from "../Keyboard"; import { ISetting } from "../settings/Settings"; import SettingsStore from "../settings/SettingsStore"; +import { + AutocompleteAction, + KeyBindingAction, + LabsAction, + MessageComposerAction, + NavigationAction, + RoomAction, + RoomListAction, +} from "../KeyBindingsManager"; -interface IKeyboardShortcuts { - [setting: string]: ISetting; -} +type IKeyboardShortcuts = { + // TODO: We should figure out what to do with the keyboard shortcuts that are not handled by KeybindingManager + [k in (KeyBindingAction | string)]: ISetting; +}; export interface ICategory { categoryLabel: string; - settingNames: string[]; + // TODO: We should figure out what to do with the keyboard shortcuts that are not handled by KeybindingManager + settingNames: (KeyBindingAction | string)[]; } export enum CategoryName { @@ -70,20 +81,20 @@ export const CATEGORIES: Record = { [CategoryName.COMPOSER]: { categoryLabel: _td("Composer"), settingNames: [ - "KeyBinding.sendMessageInComposer", - "KeyBinding.toggleBoldInComposer", - "KeyBinding.toggleItalicsInComposer", - "KeyBinding.toggleQuoteInComposer", - "KeyBinding.newLineInComposer", - "KeyBinding.cancelReplyInComposer", - "KeyBinding.editNextMessage", - "KeyBinding.editPreviousMessage", - "KeyBinding.jumpToStartInComposer", - "KeyBinding.jumpToEndInComposer", - "KeyBinding.nextMessageInComposerHistory", - "KeyBinding.previousMessageInComposerHistory", - "KeyBinding.editUndoInComposer", - "KeyBinding.editRedoInComposer", + MessageComposerAction.Send, + MessageComposerAction.FormatBold, + MessageComposerAction.FormatItalics, + MessageComposerAction.FormatQuote, + MessageComposerAction.NewLine, + MessageComposerAction.CancelEditing, + MessageComposerAction.EditNextMessage, + MessageComposerAction.EditPrevMessage, + MessageComposerAction.MoveCursorToStart, + MessageComposerAction.MoveCursorToEnd, + MessageComposerAction.SelectNextSendHistory, + MessageComposerAction.EditPrevMessage, + MessageComposerAction.EditUndo, + MessageComposerAction.EditRedo, ], }, [CategoryName.CALLS]: { categoryLabel: _td("Calls"), @@ -94,54 +105,54 @@ export const CATEGORIES: Record = { }, [CategoryName.ROOM]: { categoryLabel: _td("Room"), settingNames: [ - "KeyBinding.dismissReadMarkerAndJumpToBottom", - "KeyBinding.jumpToOldestUnreadMessage", - "KeyBinding.uploadFileToRoom", - "KeyBinding.searchInRoom", - "KeyBinding.scrollUpInTimeline", - "KeyBinding.scrollDownInTimeline", - "KeyBinding.jumpToFirstMessageInTimeline", - "KeyBinding.jumpToLastMessageInTimeline", + RoomAction.DismissReadMarker, + RoomAction.JumpToOldestUnread, + RoomAction.UploadFile, + RoomAction.FocusSearch, + RoomAction.ScrollUp, + RoomAction.RoomScrollDown, + RoomAction.JumpToFirstMessage, + RoomAction.JumpToLatestMessage, ], }, [CategoryName.ROOM_LIST]: { categoryLabel: _td("Room List"), settingNames: [ - "KeyBinding.selectRoomInRoomList", - "KeyBinding.collapseSectionInRoomList", - "KeyBinding.expandSectionInRoomList", - "KeyBinding.clearRoomFilter", - "KeyBinding.upperRoom", - "KeyBinding.downerRoom", + RoomListAction.SelectRoom, + RoomListAction.CollapseSection, + RoomListAction.ExpandSection, + RoomListAction.ClearSearch, + RoomListAction.NextRoom, + RoomListAction.PrevRoom, ], }, [CategoryName.NAVIGATION]: { categoryLabel: _td("Navigation"), settingNames: [ - "KeyBinding.toggleTopLeftMenu", + NavigationAction.ToggleUserMenu, "KeyBinding.closeDialogOrContextMenu", "KeyBinding.activateSelectedButton", - "KeyBinding.toggleRightPanel", - "KeyBinding.showKeyBindingsSettings", - "KeyBinding.goToHomeView", - "KeyBinding.nextUnreadRoom", - "KeyBinding.previousUnreadRoom", - "KeyBinding.nextRoom", - "KeyBinding.previousRoom", - "KeyBinding.toggleSpacePanel", - "KeyBinding.filterRooms", + NavigationAction.ToggleRoomSidePanel, + NavigationAction.OpenShortCutDialog, + NavigationAction.GoToHome, + NavigationAction.SelectNextUnreadRoom, + NavigationAction.SelectPrevUnreadRoom, + NavigationAction.SelectNextRoom, + NavigationAction.SelectPrevRoom, + NavigationAction.ToggleSpacePanel, + NavigationAction.FocusRoomSearch, ], }, [CategoryName.AUTOCOMPLETE]: { categoryLabel: _td("Autocomplete"), settingNames: [ - "KeyBinding.cancelAutoComplete", - "KeyBinding.nextOptionInAutoComplete", - "KeyBinding.previousOptionInAutoComplete", - "KeyBinding.completeAutocomplete", - "KeyBinding.forceCompleteAutocomplete", + AutocompleteAction.Cancel, + AutocompleteAction.NextSelection, + AutocompleteAction.PrevSelection, + AutocompleteAction.Complete, + AutocompleteAction.ForceComplete, ], }, [CategoryName.LABS]: { categoryLabel: _td("Labs"), settingNames: [ - "KeyBinding.toggleHiddenEventVisibility", + LabsAction.ToggleHiddenEventVisibility, ], }, }; @@ -150,60 +161,60 @@ export const CATEGORIES: Record = { // to implement customizable keyboard shortcuts // TODO: TravisR will fix this nightmare when the new version of the SettingsStore becomes a thing const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { - "KeyBinding.toggleBoldInComposer": { + [MessageComposerAction.FormatBold]: { default: { ctrlOrCmdKey: true, key: Key.B, }, displayName: _td("Toggle Bold"), }, - "KeyBinding.toggleItalicsInComposer": { + [MessageComposerAction.FormatItalics]: { default: { ctrlOrCmdKey: true, key: Key.I, }, displayName: _td("Toggle Italics"), }, - "KeyBinding.toggleQuoteInComposer": { + [MessageComposerAction.FormatQuote]: { default: { ctrlOrCmdKey: true, key: Key.GREATER_THAN, }, displayName: _td("Toggle Quote"), }, - "KeyBinding.cancelReplyInComposer": { + [MessageComposerAction.CancelEditing]: { default: { key: Key.ESCAPE, }, displayName: _td("Cancel replying to a message"), }, - "KeyBinding.editNextMessage": { + [MessageComposerAction.EditNextMessage]: { default: { key: Key.ARROW_UP, }, displayName: _td("Navigate to next message to edit"), }, - "KeyBinding.editPreviousMessage": { + [MessageComposerAction.EditPrevMessage]: { default: { key: Key.ARROW_DOWN, }, displayName: _td("Navigate to previous message to edit"), }, - "KeyBinding.jumpToStartInComposer": { + [MessageComposerAction.MoveCursorToStart]: { default: { ctrlOrCmdKey: true, key: Key.HOME, }, displayName: _td("Jump to start of the composer"), }, - "KeyBinding.jumpToEndInComposer": { + [MessageComposerAction.MoveCursorToEnd]: { default: { ctrlOrCmdKey: true, key: Key.END, }, displayName: _td("Jump to end of the composer"), }, - "KeyBinding.nextMessageInComposerHistory": { + [MessageComposerAction.SelectNextSendHistory]: { default: { altKey: true, ctrlKey: true, @@ -211,7 +222,7 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Navigate to next message in composer history"), }, - "KeyBinding.previousMessageInComposerHistory": { + [MessageComposerAction.SelectPrevSendHistory]: { default: { altKey: true, ctrlKey: true, @@ -233,20 +244,20 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Toggle webcam on/off"), }, - "KeyBinding.dismissReadMarkerAndJumpToBottom": { + [RoomAction.DismissReadMarker]: { default: { key: Key.ESCAPE, }, displayName: _td("Dismiss read marker and jump to bottom"), }, - "KeyBinding.jumpToOldestUnreadMessage": { + [RoomAction.JumpToOldestUnread]: { default: { shiftKey: true, key: Key.PAGE_UP, }, displayName: _td("Jump to oldest unread message"), }, - "KeyBinding.uploadFileToRoom": { + [RoomAction.UploadFile]: { default: { ctrlOrCmdKey: true, shiftKey: true, @@ -254,69 +265,69 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Upload a file"), }, - "KeyBinding.searchInRoom": { + [RoomAction.FocusSearch]: { default: { ctrlOrCmdKey: true, key: Key.F, }, displayName: _td("Search (must be enabled)"), }, - "KeyBinding.scrollUpInTimeline": { + [RoomAction.ScrollUp]: { default: { key: Key.PAGE_UP, }, displayName: _td("Scroll up in the timeline"), }, - "KeyBinding.scrollDownInTimeline": { + [RoomAction.RoomScrollDown]: { default: { key: Key.PAGE_DOWN, }, displayName: _td("Scroll down in the timeline"), }, - "KeyBinding.filterRooms": { + [NavigationAction.FocusRoomSearch]: { default: { ctrlOrCmdKey: true, key: Key.K, }, displayName: _td("Jump to room search"), }, - "KeyBinding.selectRoomInRoomList": { + [RoomListAction.SelectRoom]: { default: { key: Key.ENTER, }, displayName: _td("Select room from the room list"), }, - "KeyBinding.collapseSectionInRoomList": { + [RoomListAction.CollapseSection]: { default: { key: Key.ARROW_LEFT, }, displayName: _td("Collapse room list section"), }, - "KeyBinding.expandSectionInRoomList": { + [RoomListAction.ExpandSection]: { default: { key: Key.ARROW_RIGHT, }, displayName: _td("Expand room list section"), }, - "KeyBinding.clearRoomFilter": { + [RoomListAction.ClearSearch]: { default: { key: Key.ESCAPE, }, displayName: _td("Clear room list filter field"), }, - "KeyBinding.upperRoom": { + [RoomListAction.NextRoom]: { default: { key: Key.ARROW_UP, }, displayName: _td("Navigate up in the room list"), }, - "KeyBinding.downerRoom": { + [RoomListAction.PrevRoom]: { default: { key: Key.ARROW_DOWN, }, displayName: _td("Navigate down in the room list"), }, - "KeyBinding.toggleTopLeftMenu": { + [NavigationAction.ToggleUserMenu]: { default: { ctrlOrCmdKey: true, key: Key.BACKTICK, @@ -335,21 +346,21 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Activate selected button"), }, - "KeyBinding.toggleRightPanel": { + [NavigationAction.ToggleRoomSidePanel]: { default: { ctrlOrCmdKey: true, key: Key.PERIOD, }, displayName: _td("Toggle right panel"), }, - "KeyBinding.showKeyBindingsSettings": { + [NavigationAction.OpenShortCutDialog]: { default: { ctrlOrCmdKey: true, key: Key.SLASH, }, displayName: _td("Open this settings tab"), }, - "KeyBinding.goToHomeView": { + [NavigationAction.GoToHome]: { default: { ctrlOrCmdKey: true, altKey: !isMac, @@ -358,7 +369,7 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Go to Home View"), }, - "KeyBinding.nextUnreadRoom": { + [NavigationAction.SelectNextUnreadRoom]: { default: { shiftKey: true, altKey: true, @@ -366,7 +377,7 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Next unread room or DM"), }, - "KeyBinding.previousUnreadRoom": { + [NavigationAction.SelectPrevUnreadRoom]: { default: { shiftKey: true, altKey: true, @@ -374,39 +385,39 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Previous unread room or DM"), }, - "KeyBinding.nextRoom": { + [NavigationAction.SelectNextRoom]: { default: { altKey: true, key: Key.ARROW_UP, }, displayName: _td("Next room or DM"), }, - "KeyBinding.previousRoom": { + [NavigationAction.SelectPrevRoom]: { default: { altKey: true, key: Key.ARROW_DOWN, }, displayName: _td("Previous room or DM"), }, - "KeyBinding.cancelAutoComplete": { + [AutocompleteAction.Cancel]: { default: { key: Key.ESCAPE, }, displayName: _td("Cancel autocomplete"), }, - "KeyBinding.nextOptionInAutoComplete": { + [AutocompleteAction.NextSelection]: { default: { key: Key.ARROW_UP, }, displayName: _td("Next autocomplete suggestion"), }, - "KeyBinding.previousOptionInAutoComplete": { + [AutocompleteAction.PrevSelection]: { default: { key: Key.ARROW_DOWN, }, displayName: _td("Previous autocomplete suggestion"), }, - "KeyBinding.toggleSpacePanel": { + [NavigationAction.ToggleSpacePanel]: { default: { ctrlOrCmdKey: true, shiftKey: true, @@ -414,7 +425,7 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Toggle space panel"), }, - "KeyBinding.toggleHiddenEventVisibility": { + [LabsAction.ToggleHiddenEventVisibility]: { default: { ctrlOrCmdKey: true, shiftKey: true, @@ -422,34 +433,34 @@ const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = { }, displayName: _td("Toggle hidden event visibility"), }, - "KeyBinding.jumpToFirstMessageInTimeline": { + [RoomAction.JumpToFirstMessage]: { default: { key: Key.HOME, ctrlKey: true, }, displayName: _td("Jump to first message"), }, - "KeyBinding.jumpToLastMessageInTimeline": { + [RoomAction.JumpToOldestUnread]: { default: { key: Key.END, ctrlKey: true, }, displayName: _td("Jump to last message"), }, - "KeyBinding.editUndoInComposer": { + [MessageComposerAction.EditUndo]: { default: { key: Key.Z, ctrlOrCmdKey: true, }, displayName: _td("Undo edit"), }, - "KeyBinding.completeAutocomplete": { + [AutocompleteAction.Complete]: { default: { key: Key.ENTER, }, displayName: _td("Complete"), }, - "KeyBinding.forceCompleteAutocomplete": { + [AutocompleteAction.ForceComplete]: { default: { key: Key.TAB, }, @@ -461,7 +472,7 @@ export const getKeyboardShortcuts = (): IKeyboardShortcuts => { const keyboardShortcuts = KEYBOARD_SHORTCUTS; const ctrlEnterToSend = SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend'); - keyboardShortcuts["KeyBinding.sendMessageInComposer"] = { + keyboardShortcuts[MessageComposerAction.Send] = { default: { key: Key.ENTER, ctrlOrCmdKey: ctrlEnterToSend, @@ -469,14 +480,14 @@ export const getKeyboardShortcuts = (): IKeyboardShortcuts => { displayName: _td("Send message"), }; - keyboardShortcuts["KeyBinding.newLineInComposer"] = { + keyboardShortcuts[MessageComposerAction.NewLine] = { default: { key: Key.ENTER, shiftKey: !ctrlEnterToSend, }, displayName: _td("New line"), }; - keyboardShortcuts["KeyBinding.editRedoInComposer"] = { + keyboardShortcuts[MessageComposerAction.EditRedo] = { default: { key: isMac ? Key.Z : Key.Y, ctrlOrCmdKey: true, From f3cf0e42edea6ab98c77058e03ce98bae2ed757c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 26 Jan 2022 21:01:17 +0100 Subject: [PATCH 09/10] i18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/i18n/strings/en_EN.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 04ccade393a..bf3061cb8c6 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3377,7 +3377,6 @@ "Toggle Bold": "Toggle Bold", "Toggle Italics": "Toggle Italics", "Toggle Quote": "Toggle Quote", - "New line": "New line", "Cancel replying to a message": "Cancel replying to a message", "Navigate to next message to edit": "Navigate to next message to edit", "Navigate to previous message to edit": "Navigate to previous message to edit", @@ -3414,5 +3413,11 @@ "Next autocomplete suggestion": "Next autocomplete suggestion", "Previous autocomplete suggestion": "Previous autocomplete suggestion", "Toggle space panel": "Toggle space panel", - "Toggle hidden event visibility": "Toggle hidden event visibility" + "Toggle hidden event visibility": "Toggle hidden event visibility", + "Jump to first message": "Jump to first message", + "Jump to last message": "Jump to last message", + "Undo edit": "Undo edit", + "Force complete": "Force complete", + "New line": "New line", + "Redo edit": "Redo edit" } From 67d9ed5fd271b28af4f29eab3a95f37157ebaad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 27 Jan 2022 06:31:46 +0100 Subject: [PATCH 10/10] Fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- test/accessibility/KeyboardShortcuts-test.ts | 4 ++-- .../tabs/user/KeyboardUserSettingsTab-test.tsx | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/accessibility/KeyboardShortcuts-test.ts b/test/accessibility/KeyboardShortcuts-test.ts index 5fb559e1ab8..cac87367a40 100644 --- a/test/accessibility/KeyboardShortcuts-test.ts +++ b/test/accessibility/KeyboardShortcuts-test.ts @@ -17,7 +17,7 @@ limitations under the License. import { CATEGORIES, CategoryName, - KEYBOARD_SHORTCUTS, + getKeyboardShortcuts, registerShortcut, } from "../../src/accessibility/KeyboardShortcuts"; import { Key } from "../../src/Keyboard"; @@ -38,7 +38,7 @@ describe("KeyboardShortcuts", () => { registerShortcut(shortcutName, shortcutCategory, shortcut); - expect(KEYBOARD_SHORTCUTS[shortcutName]).toBe(shortcut); + expect(getKeyboardShortcuts()[shortcutName]).toBe(shortcut); expect(CATEGORIES[shortcutCategory].settingNames.includes(shortcutName)).toBeTruthy(); }); }); diff --git a/test/components/views/settings/tabs/user/KeyboardUserSettingsTab-test.tsx b/test/components/views/settings/tabs/user/KeyboardUserSettingsTab-test.tsx index 2297ada27a3..a3e367fd752 100644 --- a/test/components/views/settings/tabs/user/KeyboardUserSettingsTab-test.tsx +++ b/test/components/views/settings/tabs/user/KeyboardUserSettingsTab-test.tsx @@ -60,7 +60,7 @@ describe("KeyboardUserSettingsTab", () => { it("doesn't render same modifier twice", async () => { mockKeyboardShortcuts({ - "KEYBOARD_SHORTCUTS": { + "getKeyboardShortcuts": () => ({ "keybind1": { default: { key: Key.A, @@ -69,14 +69,14 @@ describe("KeyboardUserSettingsTab", () => { }, displayName: "Cancel replying to a message", }, - }, + }), }); const body1 = await renderKeyboardUserSettingsTab("KeyboardShortcut", { name: "keybind1" }); expect(body1).toMatchSnapshot(); jest.resetModules(); mockKeyboardShortcuts({ - "KEYBOARD_SHORTCUTS": { + "getKeyboardShortcuts": () => ({ "keybind1": { default: { key: Key.A, @@ -85,7 +85,7 @@ describe("KeyboardUserSettingsTab", () => { }, displayName: "Cancel replying to a message", }, - }, + }), }); const body2 = await renderKeyboardUserSettingsTab("KeyboardShortcut", { name: "keybind1" }); expect(body2).toMatchSnapshot(); @@ -94,7 +94,7 @@ describe("KeyboardUserSettingsTab", () => { it("renders list of keyboard shortcuts", async () => { mockKeyboardShortcuts({ - "KEYBOARD_SHORTCUTS": { + "getKeyboardShortcuts": () => ({ "keybind1": { default: { key: Key.A, @@ -115,7 +115,7 @@ describe("KeyboardUserSettingsTab", () => { }, displayName: "Select room from the room list", }, - }, + }), "CATEGORIES": { "Composer": { settingNames: ["keybind1", "keybind2"],