mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-15 20:54:59 +08:00
This commit is contained in:
parent
f2249b3e37
commit
57a5647079
@ -20,117 +20,121 @@ 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',
|
||||
}
|
||||
|
||||
export type KeyBindingAction = (
|
||||
MessageComposerAction | AutocompleteAction | RoomListAction | RoomAction | NavigationAction | LabsAction
|
||||
);
|
||||
|
||||
/**
|
||||
* Represent a key combination.
|
||||
*
|
||||
|
@ -18,10 +18,26 @@ limitations under the License.
|
||||
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";
|
||||
|
||||
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 {
|
||||
@ -65,17 +81,20 @@ export const CATEGORIES: Record<CategoryName, ICategory> = {
|
||||
[CategoryName.COMPOSER]: {
|
||||
categoryLabel: _td("Composer"),
|
||||
settingNames: [
|
||||
"KeyBinding.toggleBoldInComposer",
|
||||
"KeyBinding.toggleItalicsInComposer",
|
||||
"KeyBinding.toggleQuoteInComposer",
|
||||
"KeyBinding.newLineInComposer",
|
||||
"KeyBinding.cancelReplyInComposer",
|
||||
"KeyBinding.editNextMessage",
|
||||
"KeyBinding.editPreviousMessage",
|
||||
"KeyBinding.jumpToStartInComposer",
|
||||
"KeyBinding.jumpToEndInComposer",
|
||||
"KeyBinding.nextMessageInComposerHistory",
|
||||
"KeyBinding.previousMessageInComposerHistory",
|
||||
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"),
|
||||
@ -86,50 +105,54 @@ export const CATEGORIES: Record<CategoryName, ICategory> = {
|
||||
}, [CategoryName.ROOM]: {
|
||||
categoryLabel: _td("Room"),
|
||||
settingNames: [
|
||||
"KeyBinding.dismissReadMarkerAndJumpToBottom",
|
||||
"KeyBinding.jumpToOldestUnreadMessage",
|
||||
"KeyBinding.uploadFileToRoom",
|
||||
"KeyBinding.searchInRoom",
|
||||
"KeyBinding.scrollUpInTimeline",
|
||||
"KeyBinding.scrollDownInTimeline",
|
||||
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.filterRooms",
|
||||
"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",
|
||||
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",
|
||||
AutocompleteAction.Cancel,
|
||||
AutocompleteAction.NextSelection,
|
||||
AutocompleteAction.PrevSelection,
|
||||
AutocompleteAction.Complete,
|
||||
AutocompleteAction.ForceComplete,
|
||||
],
|
||||
}, [CategoryName.LABS]: {
|
||||
categoryLabel: _td("Labs"),
|
||||
settingNames: [
|
||||
"KeyBinding.toggleHiddenEventVisibility",
|
||||
LabsAction.ToggleHiddenEventVisibility,
|
||||
],
|
||||
},
|
||||
};
|
||||
@ -137,68 +160,61 @@ export const CATEGORIES: Record<CategoryName, ICategory> = {
|
||||
// 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 } = {
|
||||
"KeyBinding.toggleBoldInComposer": {
|
||||
const KEYBOARD_SHORTCUTS: IKeyboardShortcuts = {
|
||||
[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.newLineInComposer": {
|
||||
default: {
|
||||
shiftKey: true,
|
||||
key: Key.ENTER,
|
||||
},
|
||||
displayName: _td("New line"),
|
||||
},
|
||||
"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,
|
||||
@ -206,7 +222,7 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
displayName: _td("Navigate to next message in composer history"),
|
||||
},
|
||||
"KeyBinding.previousMessageInComposerHistory": {
|
||||
[MessageComposerAction.SelectPrevSendHistory]: {
|
||||
default: {
|
||||
altKey: true,
|
||||
ctrlKey: true,
|
||||
@ -228,20 +244,20 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
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,
|
||||
@ -249,69 +265,69 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
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,
|
||||
@ -330,21 +346,21 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
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,
|
||||
@ -353,7 +369,7 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
displayName: _td("Go to Home View"),
|
||||
},
|
||||
"KeyBinding.nextUnreadRoom": {
|
||||
[NavigationAction.SelectNextUnreadRoom]: {
|
||||
default: {
|
||||
shiftKey: true,
|
||||
altKey: true,
|
||||
@ -361,7 +377,7 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
displayName: _td("Next unread room or DM"),
|
||||
},
|
||||
"KeyBinding.previousUnreadRoom": {
|
||||
[NavigationAction.SelectPrevUnreadRoom]: {
|
||||
default: {
|
||||
shiftKey: true,
|
||||
altKey: true,
|
||||
@ -369,39 +385,39 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
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,
|
||||
@ -409,7 +425,7 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
displayName: _td("Toggle space panel"),
|
||||
},
|
||||
"KeyBinding.toggleHiddenEventVisibility": {
|
||||
[LabsAction.ToggleHiddenEventVisibility]: {
|
||||
default: {
|
||||
ctrlOrCmdKey: true,
|
||||
shiftKey: true,
|
||||
@ -417,6 +433,70 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
|
||||
},
|
||||
displayName: _td("Toggle hidden event visibility"),
|
||||
},
|
||||
[RoomAction.JumpToFirstMessage]: {
|
||||
default: {
|
||||
key: Key.HOME,
|
||||
ctrlKey: true,
|
||||
},
|
||||
displayName: _td("Jump to first message"),
|
||||
},
|
||||
[RoomAction.JumpToOldestUnread]: {
|
||||
default: {
|
||||
key: Key.END,
|
||||
ctrlKey: true,
|
||||
},
|
||||
displayName: _td("Jump to last message"),
|
||||
},
|
||||
[MessageComposerAction.EditUndo]: {
|
||||
default: {
|
||||
key: Key.Z,
|
||||
ctrlOrCmdKey: true,
|
||||
},
|
||||
displayName: _td("Undo edit"),
|
||||
},
|
||||
[AutocompleteAction.Complete]: {
|
||||
default: {
|
||||
key: Key.ENTER,
|
||||
},
|
||||
displayName: _td("Complete"),
|
||||
},
|
||||
[AutocompleteAction.ForceComplete]: {
|
||||
default: {
|
||||
key: Key.TAB,
|
||||
},
|
||||
displayName: _td("Force complete"),
|
||||
},
|
||||
};
|
||||
|
||||
export const getKeyboardShortcuts = (): IKeyboardShortcuts => {
|
||||
const keyboardShortcuts = KEYBOARD_SHORTCUTS;
|
||||
const ctrlEnterToSend = SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend');
|
||||
|
||||
keyboardShortcuts[MessageComposerAction.Send] = {
|
||||
default: {
|
||||
key: Key.ENTER,
|
||||
ctrlOrCmdKey: ctrlEnterToSend,
|
||||
},
|
||||
displayName: _td("Send message"),
|
||||
|
||||
};
|
||||
keyboardShortcuts[MessageComposerAction.NewLine] = {
|
||||
default: {
|
||||
key: Key.ENTER,
|
||||
shiftKey: !ctrlEnterToSend,
|
||||
},
|
||||
displayName: _td("New line"),
|
||||
};
|
||||
keyboardShortcuts[MessageComposerAction.EditRedo] = {
|
||||
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 => {
|
||||
|
@ -18,7 +18,7 @@ limitations under the License.
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
KEYBOARD_SHORTCUTS,
|
||||
getKeyboardShortcuts,
|
||||
ALTERNATE_KEY_NAME,
|
||||
KEY_ICON,
|
||||
ICategory,
|
||||
@ -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 getKeyboardShortcuts()[name]?.default;
|
||||
};
|
||||
|
||||
const getKeyboardShortcutDisplayName = (name: string): string => {
|
||||
return getKeyboardShortcuts()[name]?.displayName as string;
|
||||
};
|
||||
|
||||
interface IKeyboardKeyProps {
|
||||
name: string;
|
||||
last?: boolean;
|
||||
@ -49,7 +58,7 @@ interface IKeyboardShortcutProps {
|
||||
}
|
||||
|
||||
export const KeyboardShortcut: React.FC<IKeyboardShortcutProps> = ({ 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<IKeyboardShortcutRowProps> = ({ name }) => {
|
||||
return <div className="mx_KeyboardShortcut_shortcutRow">
|
||||
{ KEYBOARD_SHORTCUTS[name].displayName }
|
||||
{ getKeyboardShortcutDisplayName(name) }
|
||||
<KeyboardShortcut name={name} />
|
||||
</div>;
|
||||
};
|
||||
|
@ -3379,7 +3379,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",
|
||||
@ -3416,5 +3415,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"
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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"],
|
||||
|
Loading…
Reference in New Issue
Block a user