diff --git a/src/KeyBindingsManager.ts b/src/KeyBindingsManager.ts index b969982bda..d8c128a2bf 100644 --- a/src/KeyBindingsManager.ts +++ b/src/KeyBindingsManager.ts @@ -1,24 +1,8 @@ import { isMac, Key } from './Keyboard'; import SettingsStore from './settings/SettingsStore'; -export enum KeyBindingContext { - /** Key bindings for the chat message composer component */ - MessageComposer = 'MessageComposer', - /** Key bindings for text editing autocompletion */ - AutoComplete = 'AutoComplete', - /** Left room list sidebar */ - RoomList = 'RoomList', - /** Current room view */ - Room = 'Room', - /** Shortcuts to navigate do various menus / dialogs / screens */ - Navigation = 'Navigation', -} - -export enum KeyAction { - None = 'None', - - // SendMessageComposer actions: - +/** Actions for the chat message composer component */ +export enum MessageComposerAction { /** Send a message */ Send = 'Send', /** Go backwards through the send history and use the message in composer view */ @@ -46,70 +30,74 @@ export enum KeyAction { NewLine = 'NewLine', MoveCursorToStart = 'MoveCursorToStart', MoveCursorToEnd = 'MoveCursorToEnd', +} - // Autocomplete - +/** Actions for text editing autocompletion */ +export enum AutocompleteAction { /** Apply the current autocomplete selection */ - AutocompleteApply = 'AutocompleteApply', + ApplySelection = 'ApplySelection', /** Cancel autocompletion */ - AutocompleteCancel = 'AutocompleteCancel', + Cancel = 'Cancel', /** Move to the previous autocomplete selection */ - AutocompletePrevSelection = 'AutocompletePrevSelection', + PrevSelection = 'PrevSelection', /** Move to the next autocomplete selection */ - AutocompleteNextSelection = 'AutocompleteNextSelection', - - // Room list + NextSelection = 'NextSelection', +} +/** Actions for the left room list sidebar */ +export enum RoomListAction { /** Clear room list filter field */ - RoomListClearSearch = 'RoomListClearSearch', + ClearSearch = 'ClearSearch', /** Navigate up/down in the room list */ - RoomListPrevRoom = 'RoomListPrevRoom', + PrevRoom = 'PrevRoom', /** Navigate down in the room list */ - RoomListNextRoom = 'RoomListNextRoom', + NextRoom = 'NextRoom', /** Select room from the room list */ - RoomListSelectRoom = 'RoomListSelectRoom', + SelectRoom = 'SelectRoom', /** Collapse room list section */ - RoomListCollapseSection = 'RoomListCollapseSection', + CollapseSection = 'CollapseSection', /** Expand room list section, if already expanded, jump to first room in the selection */ - RoomListExpandSection = 'RoomListExpandSection', + ExpandSection = 'ExpandSection', +} - // Room - - /** Jump to room search */ - RoomFocusRoomSearch = 'RoomFocusRoomSearch', +/** Actions for the current room view */ +export enum RoomAction { + /** Jump to room search (search for a room)*/ + FocusRoomSearch = 'FocusRoomSearch', // TODO: move to NavigationAction? /** Scroll up in the timeline */ - RoomScrollUp = 'RoomScrollUp', + ScrollUp = 'ScrollUp', /** Scroll down in the timeline */ RoomScrollDown = 'RoomScrollDown', /** Dismiss read marker and jump to bottom */ - RoomDismissReadMarker = 'RoomDismissReadMarker', + DismissReadMarker = 'DismissReadMarker', /* Upload a file */ - RoomUploadFile = 'RoomUploadFile', - /* Search (must be enabled) */ - RoomSearch = 'RoomSearch', + UploadFile = 'UploadFile', + /* Focus search message in a room (must be enabled) */ + FocusSearch = 'FocusSearch', /* Jump to the first (downloaded) message in the room */ - RoomJumpToFirstMessage = 'RoomJumpToFirstMessage', + JumpToFirstMessage = 'JumpToFirstMessage', /* Jump to the latest message in the room */ - RoomJumpToLatestMessage = 'RoomJumpToLatestMessage', - - // Navigation + JumpToLatestMessage = 'JumpToLatestMessage', +} +/** Actions for navigating do various menus / dialogs / screens */ +export enum NavigationAction { /** Toggle the room side panel */ - NavToggleRoomSidePanel = 'NavToggleRoomSidePanel', + ToggleRoomSidePanel = 'ToggleRoomSidePanel', /** Toggle the user menu */ - NavToggleUserMenu = 'NavToggleUserMenu', + ToggleUserMenu = 'ToggleUserMenu', /* Toggle the short cut help dialog */ - NavToggleShortCutDialog = 'NavToggleShortCutDialog', + ToggleShortCutDialog = 'ToggleShortCutDialog', /* Got to the Element home screen */ - NavGoToHome = 'NavGoToHome', + GoToHome = 'GoToHome', /* Select prev room */ - NavSelectPrevRoom = 'NavSelectPrevRoom', + SelectPrevRoom = 'SelectPrevRoom', /* Select next room */ - NavSelectNextRoom = 'NavSelectNextRoom', + SelectNextRoom = 'SelectNextRoom', /* Select prev room with unread messages*/ - NavSelectPrevUnreadRoom = 'NavSelectPrevUnreadRoom', + SelectPrevUnreadRoom = 'SelectPrevUnreadRoom', /* Select next room with unread messages*/ - NavSelectNextUnreadRoom = 'NavSelectNextUnreadRoom', + SelectNextUnreadRoom = 'SelectNextUnreadRoom', } /** @@ -129,15 +117,15 @@ export type KeyCombo = { shiftKey?: boolean; } -export type KeyBinding = { - action: KeyAction; +export type KeyBinding = { + action: T; keyCombo: KeyCombo; } -const messageComposerBindings = (): KeyBinding[] => { - const bindings: KeyBinding[] = [ +const messageComposerBindings = (): KeyBinding[] => { + const bindings: KeyBinding[] = [ { - action: KeyAction.SelectPrevSendHistory, + action: MessageComposerAction.SelectPrevSendHistory, keyCombo: { key: Key.ARROW_UP, altKey: true, @@ -145,7 +133,7 @@ const messageComposerBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.SelectNextSendHistory, + action: MessageComposerAction.SelectNextSendHistory, keyCombo: { key: Key.ARROW_DOWN, altKey: true, @@ -153,39 +141,39 @@ const messageComposerBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.EditPrevMessage, + action: MessageComposerAction.EditPrevMessage, keyCombo: { key: Key.ARROW_UP, }, }, { - action: KeyAction.EditNextMessage, + action: MessageComposerAction.EditNextMessage, keyCombo: { key: Key.ARROW_DOWN, }, }, { - action: KeyAction.CancelEditing, + action: MessageComposerAction.CancelEditing, keyCombo: { key: Key.ESCAPE, }, }, { - action: KeyAction.FormatBold, + action: MessageComposerAction.FormatBold, keyCombo: { key: Key.B, ctrlOrCmd: true, }, }, { - action: KeyAction.FormatItalics, + action: MessageComposerAction.FormatItalics, keyCombo: { key: Key.I, ctrlOrCmd: true, }, }, { - action: KeyAction.FormatQuote, + action: MessageComposerAction.FormatQuote, keyCombo: { key: Key.GREATER_THAN, ctrlOrCmd: true, @@ -193,7 +181,7 @@ const messageComposerBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.EditUndo, + action: MessageComposerAction.EditUndo, keyCombo: { key: Key.Z, ctrlOrCmd: true, @@ -201,14 +189,14 @@ const messageComposerBindings = (): KeyBinding[] => { }, // Note: the following two bindings also work with just HOME and END, add them here? { - action: KeyAction.MoveCursorToStart, + action: MessageComposerAction.MoveCursorToStart, keyCombo: { key: Key.HOME, ctrlOrCmd: true, }, }, { - action: KeyAction.MoveCursorToEnd, + action: MessageComposerAction.MoveCursorToEnd, keyCombo: { key: Key.END, ctrlOrCmd: true, @@ -217,7 +205,7 @@ const messageComposerBindings = (): KeyBinding[] => { ]; if (isMac) { bindings.push({ - action: KeyAction.EditRedo, + action: MessageComposerAction.EditRedo, keyCombo: { key: Key.Z, ctrlOrCmd: true, @@ -226,7 +214,7 @@ const messageComposerBindings = (): KeyBinding[] => { }); } else { bindings.push({ - action: KeyAction.EditRedo, + action: MessageComposerAction.EditRedo, keyCombo: { key: Key.Y, ctrlOrCmd: true, @@ -235,27 +223,27 @@ const messageComposerBindings = (): KeyBinding[] => { } if (SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend')) { bindings.push({ - action: KeyAction.Send, + action: MessageComposerAction.Send, keyCombo: { key: Key.ENTER, ctrlOrCmd: true, }, }); bindings.push({ - action: KeyAction.NewLine, + action: MessageComposerAction.NewLine, keyCombo: { key: Key.ENTER, }, }); } else { bindings.push({ - action: KeyAction.Send, + action: MessageComposerAction.Send, keyCombo: { key: Key.ENTER, }, }); bindings.push({ - action: KeyAction.NewLine, + action: MessageComposerAction.NewLine, keyCombo: { key: Key.ENTER, shiftKey: true, @@ -263,7 +251,7 @@ const messageComposerBindings = (): KeyBinding[] => { }); if (isMac) { bindings.push({ - action: KeyAction.NewLine, + action: MessageComposerAction.NewLine, keyCombo: { key: Key.ENTER, altKey: true, @@ -274,42 +262,42 @@ const messageComposerBindings = (): KeyBinding[] => { return bindings; } -const autocompleteBindings = (): KeyBinding[] => { +const autocompleteBindings = (): KeyBinding[] => { return [ { - action: KeyAction.AutocompleteApply, + action: AutocompleteAction.ApplySelection, keyCombo: { key: Key.TAB, }, }, { - action: KeyAction.AutocompleteApply, + action: AutocompleteAction.ApplySelection, keyCombo: { key: Key.TAB, ctrlKey: true, }, }, { - action: KeyAction.AutocompleteApply, + action: AutocompleteAction.ApplySelection, keyCombo: { key: Key.TAB, shiftKey: true, }, }, { - action: KeyAction.AutocompleteCancel, + action: AutocompleteAction.Cancel, keyCombo: { key: Key.ESCAPE, }, }, { - action: KeyAction.AutocompletePrevSelection, + action: AutocompleteAction.PrevSelection, keyCombo: { key: Key.ARROW_UP, }, }, { - action: KeyAction.AutocompleteNextSelection, + action: AutocompleteAction.NextSelection, keyCombo: { key: Key.ARROW_DOWN, }, @@ -317,40 +305,40 @@ const autocompleteBindings = (): KeyBinding[] => { ]; } -const roomListBindings = (): KeyBinding[] => { +const roomListBindings = (): KeyBinding[] => { return [ { - action: KeyAction.RoomListClearSearch, + action: RoomListAction.ClearSearch, keyCombo: { key: Key.ESCAPE, }, }, { - action: KeyAction.RoomListPrevRoom, + action: RoomListAction.PrevRoom, keyCombo: { key: Key.ARROW_UP, }, }, { - action: KeyAction.RoomListNextRoom, + action: RoomListAction.NextRoom, keyCombo: { key: Key.ARROW_DOWN, }, }, { - action: KeyAction.RoomListSelectRoom, + action: RoomListAction.SelectRoom, keyCombo: { key: Key.ENTER, }, }, { - action: KeyAction.RoomListCollapseSection, + action: RoomListAction.CollapseSection, keyCombo: { key: Key.ARROW_LEFT, }, }, { - action: KeyAction.RoomListExpandSection, + action: RoomListAction.ExpandSection, keyCombo: { key: Key.ARROW_RIGHT, }, @@ -358,35 +346,35 @@ const roomListBindings = (): KeyBinding[] => { ]; } -const roomBindings = (): KeyBinding[] => { +const roomBindings = (): KeyBinding[] => { const bindings = [ { - action: KeyAction.RoomFocusRoomSearch, + action: RoomAction.FocusRoomSearch, keyCombo: { key: Key.K, ctrlOrCmd: true, }, }, { - action: KeyAction.RoomScrollUp, + action: RoomAction.ScrollUp, keyCombo: { key: Key.PAGE_UP, }, }, { - action: KeyAction.RoomScrollDown, + action: RoomAction.RoomScrollDown, keyCombo: { key: Key.PAGE_DOWN, }, }, { - action: KeyAction.RoomDismissReadMarker, + action: RoomAction.DismissReadMarker, keyCombo: { key: Key.ESCAPE, }, }, { - action: KeyAction.RoomUploadFile, + action: RoomAction.UploadFile, keyCombo: { key: Key.U, ctrlOrCmd: true, @@ -394,14 +382,14 @@ const roomBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.RoomJumpToFirstMessage, + action: RoomAction.JumpToFirstMessage, keyCombo: { key: Key.HOME, ctrlKey: true, }, }, { - action: KeyAction.RoomJumpToLatestMessage, + action: RoomAction.JumpToLatestMessage, keyCombo: { key: Key.END, ctrlKey: true, @@ -411,7 +399,7 @@ const roomBindings = (): KeyBinding[] => { if (SettingsStore.getValue('ctrlFForSearch')) { bindings.push({ - action: KeyAction.RoomSearch, + action: RoomAction.FocusSearch, keyCombo: { key: Key.F, ctrlOrCmd: true, @@ -422,17 +410,17 @@ const roomBindings = (): KeyBinding[] => { return bindings; } -const navigationBindings = (): KeyBinding[] => { +const navigationBindings = (): KeyBinding[] => { return [ { - action: KeyAction.NavToggleRoomSidePanel, + action: NavigationAction.ToggleRoomSidePanel, keyCombo: { key: Key.PERIOD, ctrlOrCmd: true, }, }, { - action: KeyAction.NavToggleUserMenu, + action: NavigationAction.ToggleUserMenu, // Ideally this would be CTRL+P for "Profile", but that's // taken by the print dialog. CTRL+I for "Information" // was previously chosen but conflicted with italics in @@ -443,14 +431,14 @@ const navigationBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.NavToggleShortCutDialog, + action: NavigationAction.ToggleShortCutDialog, keyCombo: { key: Key.SLASH, ctrlOrCmd: true, }, }, { - action: KeyAction.NavToggleShortCutDialog, + action: NavigationAction.ToggleShortCutDialog, keyCombo: { key: Key.SLASH, ctrlOrCmd: true, @@ -458,7 +446,7 @@ const navigationBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.NavGoToHome, + action: NavigationAction.GoToHome, keyCombo: { key: Key.H, ctrlOrCmd: true, @@ -467,21 +455,21 @@ const navigationBindings = (): KeyBinding[] => { }, { - action: KeyAction.NavSelectPrevRoom, + action: NavigationAction.SelectPrevRoom, keyCombo: { key: Key.ARROW_UP, altKey: true, }, }, { - action: KeyAction.NavSelectNextRoom, + action: NavigationAction.SelectNextRoom, keyCombo: { key: Key.ARROW_DOWN, altKey: true, }, }, { - action: KeyAction.NavSelectPrevUnreadRoom, + action: NavigationAction.SelectPrevUnreadRoom, keyCombo: { key: Key.ARROW_UP, altKey: true, @@ -489,7 +477,7 @@ const navigationBindings = (): KeyBinding[] => { }, }, { - action: KeyAction.NavSelectNextUnreadRoom, + action: NavigationAction.SelectNextUnreadRoom, keyCombo: { key: Key.ARROW_DOWN, altKey: true, @@ -551,38 +539,42 @@ export function isKeyComboMatch(ev: KeyboardEvent | React.KeyboardEvent, combo: return true; } - -export type KeyBindingsGetter = () => KeyBinding[]; - export class KeyBindingsManager { - /** - * Map of KeyBindingContext to a KeyBinding getter arrow function. - * - * Returning a getter function allowed to have dynamic bindings, e.g. when settings change the bindings can be - * recalculated. - */ - contextBindings: Record = { - [KeyBindingContext.MessageComposer]: messageComposerBindings, - [KeyBindingContext.AutoComplete]: autocompleteBindings, - [KeyBindingContext.RoomList]: roomListBindings, - [KeyBindingContext.Room]: roomBindings, - [KeyBindingContext.Navigation]: navigationBindings, - }; - /** * Finds a matching KeyAction for a given KeyboardEvent */ - getAction(context: KeyBindingContext, ev: KeyboardEvent | React.KeyboardEvent): KeyAction { - const bindings = this.contextBindings[context]?.(); - if (!bindings) { - return KeyAction.None; - } + private getAction(bindings: KeyBinding[], ev: KeyboardEvent | React.KeyboardEvent) + : T | undefined { const binding = bindings.find(it => isKeyComboMatch(ev, it.keyCombo, isMac)); if (binding) { return binding.action; } + return undefined; + } - return KeyAction.None; + getMessageComposerAction(ev: KeyboardEvent | React.KeyboardEvent): MessageComposerAction | undefined { + const bindings = messageComposerBindings(); + return this.getAction(bindings, ev); + } + + getAutocompleteAction(ev: KeyboardEvent | React.KeyboardEvent): AutocompleteAction | undefined { + const bindings = autocompleteBindings(); + return this.getAction(bindings, ev); + } + + getRoomListAction(ev: KeyboardEvent | React.KeyboardEvent): RoomListAction | undefined { + const bindings = roomListBindings(); + return this.getAction(bindings, ev); + } + + getRoomAction(ev: KeyboardEvent | React.KeyboardEvent): RoomAction | undefined { + const bindings = roomBindings(); + return this.getAction(bindings, ev); + } + + getNavigationAction(ev: KeyboardEvent | React.KeyboardEvent): NavigationAction | undefined { + const bindings = navigationBindings(); + return this.getAction(bindings, ev); } } diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index dd8bc1f3db..ce5df47138 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -55,7 +55,7 @@ import { IThreepidInvite } from "../../stores/ThreepidInviteStore"; import Modal from "../../Modal"; import { ICollapseConfig } from "../../resizer/distributors/collapse"; import HostSignupContainer from '../views/host_signup/HostSignupContainer'; -import { getKeyBindingsManager, KeyAction, KeyBindingContext } from '../../KeyBindingsManager'; +import { getKeyBindingsManager, NavigationAction, RoomAction } from '../../KeyBindingsManager'; // We need to fetch each pinned message individually (if we don't already have it) // so each pinned message may trigger a request. Limit the number per room for sanity. @@ -401,22 +401,22 @@ class LoggedInView extends React.Component { _onKeyDown = (ev) => { let handled = false; - const roomAction = getKeyBindingsManager().getAction(KeyBindingContext.Room, ev); + const roomAction = getKeyBindingsManager().getRoomAction(ev); switch (roomAction) { - case KeyAction.RoomFocusRoomSearch: + case RoomAction.FocusRoomSearch: dis.dispatch({ action: 'focus_room_filter', }); handled = true; break; - case KeyAction.RoomScrollUp: - case KeyAction.RoomScrollDown: - case KeyAction.RoomJumpToFirstMessage: - case KeyAction.RoomJumpToLatestMessage: + case RoomAction.ScrollUp: + case RoomAction.RoomScrollDown: + case RoomAction.JumpToFirstMessage: + case RoomAction.JumpToLatestMessage: this._onScrollKeyPressed(ev); handled = true; break; - case KeyAction.RoomSearch: + case RoomAction.FocusSearch: dis.dispatch({ action: 'focus_search', }); @@ -429,24 +429,24 @@ class LoggedInView extends React.Component { return; } - const navAction = getKeyBindingsManager().getAction(KeyBindingContext.Navigation, ev); + const navAction = getKeyBindingsManager().getNavigationAction(ev); switch (navAction) { - case KeyAction.NavToggleUserMenu: + case NavigationAction.ToggleUserMenu: dis.fire(Action.ToggleUserMenu); handled = true; break; - case KeyAction.NavToggleShortCutDialog: + case NavigationAction.ToggleShortCutDialog: KeyboardShortcuts.toggleDialog(); handled = true; break; - case KeyAction.NavGoToHome: + case NavigationAction.GoToHome: dis.dispatch({ action: 'view_home_page', }); Modal.closeCurrentModal("homeKeyboardShortcut"); handled = true; break; - case KeyAction.NavToggleRoomSidePanel: + case NavigationAction.ToggleRoomSidePanel: if (this.props.page_type === "room_view" || this.props.page_type === "group_view") { dis.dispatch({ action: Action.ToggleRightPanel, @@ -455,7 +455,7 @@ class LoggedInView extends React.Component { handled = true; } break; - case KeyAction.NavSelectPrevRoom: + case NavigationAction.SelectPrevRoom: dis.dispatch({ action: Action.ViewRoomDelta, delta: -1, @@ -463,7 +463,7 @@ class LoggedInView extends React.Component { }); handled = true; break; - case KeyAction.NavSelectNextRoom: + case NavigationAction.SelectNextRoom: dis.dispatch({ action: Action.ViewRoomDelta, delta: 1, @@ -471,14 +471,14 @@ class LoggedInView extends React.Component { }); handled = true; break; - case KeyAction.NavSelectPrevUnreadRoom: + case NavigationAction.SelectPrevUnreadRoom: dis.dispatch({ action: Action.ViewRoomDelta, delta: -1, unread: true, }); break; - case KeyAction.NavSelectNextUnreadRoom: + case NavigationAction.SelectNextUnreadRoom: dis.dispatch({ action: Action.ViewRoomDelta, delta: 1, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index 2e900d2f0e..7d127040eb 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -24,7 +24,7 @@ import AccessibleButton from "../views/elements/AccessibleButton"; import { Action } from "../../dispatcher/actions"; import RoomListStore from "../../stores/room-list/RoomListStore"; import { NameFilterCondition } from "../../stores/room-list/filters/NameFilterCondition"; -import { getKeyBindingsManager, KeyAction, KeyBindingContext } from "../../KeyBindingsManager"; +import { getKeyBindingsManager, RoomListAction } from "../../KeyBindingsManager"; interface IProps { isMinimized: boolean; @@ -106,17 +106,17 @@ export default class RoomSearch extends React.PureComponent { }; private onKeyDown = (ev: React.KeyboardEvent) => { - const action = getKeyBindingsManager().getAction(KeyBindingContext.RoomList, ev); + const action = getKeyBindingsManager().getRoomListAction(ev); switch (action) { - case KeyAction.RoomListClearSearch: + case RoomListAction.ClearSearch: this.clearInput(); defaultDispatcher.fire(Action.FocusComposer); break; - case KeyAction.RoomListNextRoom: - case KeyAction.RoomListPrevRoom: + case RoomListAction.NextRoom: + case RoomListAction.PrevRoom: this.props.onVerticalArrow(ev); break; - case KeyAction.RoomListSelectRoom: { + case RoomListAction.SelectRoom: { const shouldClear = this.props.onEnter(ev); if (shouldClear) { // wrap in set immediate to delay it so that we don't clear the filter & then change room diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index c09f1f7c45..680d717615 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -78,7 +78,7 @@ import Notifier from "../../Notifier"; import { showToast as showNotificationsToast } from "../../toasts/DesktopNotificationsToast"; import { RoomNotificationStateStore } from "../../stores/notifications/RoomNotificationStateStore"; import { Container, WidgetLayoutStore } from "../../stores/widgets/WidgetLayoutStore"; -import { getKeyBindingsManager, KeyAction, KeyBindingContext } from '../../KeyBindingsManager'; +import { getKeyBindingsManager, RoomAction } from '../../KeyBindingsManager'; const DEBUG = false; let debuglog = function(msg: string) {}; @@ -661,18 +661,18 @@ export default class RoomView extends React.Component { private onReactKeyDown = ev => { let handled = false; - const action = getKeyBindingsManager().getAction(KeyBindingContext.Room, ev); + const action = getKeyBindingsManager().getRoomAction(ev); switch (action) { - case KeyAction.RoomDismissReadMarker: + case RoomAction.DismissReadMarker: this.messagePanel.forgetReadMarker(); this.jumpToLiveTimeline(); handled = true; break; - case KeyAction.RoomScrollUp: + case RoomAction.ScrollUp: this.jumpToReadMarker(); handled = true; break; - case KeyAction.RoomUploadFile: + case RoomAction.UploadFile: dis.dispatch({ action: "upload_file" }, true); handled = true; break; diff --git a/src/components/views/rooms/BasicMessageComposer.tsx b/src/components/views/rooms/BasicMessageComposer.tsx index d0119ddc05..f5e561f15a 100644 --- a/src/components/views/rooms/BasicMessageComposer.tsx +++ b/src/components/views/rooms/BasicMessageComposer.tsx @@ -46,7 +46,7 @@ import {IDiff} from "../../../editor/diff"; import AutocompleteWrapperModel from "../../../editor/autocomplete"; import DocumentPosition from "../../../editor/position"; import {ICompletion} from "../../../autocomplete/Autocompleter"; -import { getKeyBindingsManager, KeyBindingContext, KeyAction } from '../../../KeyBindingsManager'; +import { AutocompleteAction, getKeyBindingsManager, MessageComposerAction } from '../../../KeyBindingsManager'; // matches emoticons which follow the start of a line or whitespace const REGEX_EMOTICON_WHITESPACE = new RegExp('(?:^|\\s)(' + EMOTICON_REGEX.source + ')\\s$'); @@ -421,21 +421,21 @@ export default class BasicMessageEditor extends React.Component private onKeyDown = (event: React.KeyboardEvent) => { const model = this.props.model; let handled = false; - const action = getKeyBindingsManager().getAction(KeyBindingContext.MessageComposer, event); + const action = getKeyBindingsManager().getMessageComposerAction(event); switch (action) { - case KeyAction.FormatBold: + case MessageComposerAction.FormatBold: this.onFormatAction(Formatting.Bold); handled = true; break; - case KeyAction.FormatItalics: + case MessageComposerAction.FormatItalics: this.onFormatAction(Formatting.Italics); handled = true; break; - case KeyAction.FormatQuote: + case MessageComposerAction.FormatQuote: this.onFormatAction(Formatting.Quote); handled = true; break; - case KeyAction.EditRedo: + case MessageComposerAction.EditRedo: if (this.historyManager.canRedo()) { const {parts, caret} = this.historyManager.redo(); // pass matching inputType so historyManager doesn't push echo @@ -444,7 +444,7 @@ export default class BasicMessageEditor extends React.Component } handled = true; break; - case KeyAction.EditUndo: + case MessageComposerAction.EditUndo: if (this.historyManager.canUndo()) { const {parts, caret} = this.historyManager.undo(this.props.model); // pass matching inputType so historyManager doesn't push echo @@ -453,18 +453,18 @@ export default class BasicMessageEditor extends React.Component } handled = true; break; - case KeyAction.NewLine: + case MessageComposerAction.NewLine: this.insertText("\n"); handled = true; break; - case KeyAction.MoveCursorToStart: + case MessageComposerAction.MoveCursorToStart: setSelection(this.editorRef.current, model, { index: 0, offset: 0, }); handled = true; break; - case KeyAction.MoveCursorToEnd: + case MessageComposerAction.MoveCursorToEnd: setSelection(this.editorRef.current, model, { index: model.parts.length - 1, offset: model.parts[model.parts.length - 1].text.length, @@ -478,30 +478,30 @@ export default class BasicMessageEditor extends React.Component return; } - const autocompleteAction = getKeyBindingsManager().getAction(KeyBindingContext.AutoComplete, event); + const autocompleteAction = getKeyBindingsManager().getAutocompleteAction(event); if (model.autoComplete && model.autoComplete.hasCompletions()) { const autoComplete = model.autoComplete; switch (autocompleteAction) { - case KeyAction.AutocompletePrevSelection: + case AutocompleteAction.PrevSelection: autoComplete.onUpArrow(event); handled = true; break; - case KeyAction.AutocompleteNextSelection: + case AutocompleteAction.NextSelection: autoComplete.onDownArrow(event); handled = true; break; - case KeyAction.AutocompleteApply: + case AutocompleteAction.ApplySelection: autoComplete.onTab(event); handled = true; break; - case KeyAction.AutocompleteCancel: + case AutocompleteAction.Cancel: autoComplete.onEscape(event); handled = true; break; default: return; // don't preventDefault on anything else } - } else if (autocompleteAction === KeyAction.AutocompleteApply) { + } else if (autocompleteAction === AutocompleteAction.ApplySelection) { this.tabCompleteName(event); handled = true; } else if (event.key === Key.BACKSPACE || event.key === Key.DELETE) { diff --git a/src/components/views/rooms/EditMessageComposer.js b/src/components/views/rooms/EditMessageComposer.js index 8aa637f680..1cd2cc7f34 100644 --- a/src/components/views/rooms/EditMessageComposer.js +++ b/src/components/views/rooms/EditMessageComposer.js @@ -32,7 +32,7 @@ import BasicMessageComposer from "./BasicMessageComposer"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import {Action} from "../../../dispatcher/actions"; import CountlyAnalytics from "../../../CountlyAnalytics"; -import {getKeyBindingsManager, KeyAction, KeyBindingContext} from '../../../KeyBindingsManager'; +import {getKeyBindingsManager, MessageComposerAction} from '../../../KeyBindingsManager'; function _isReply(mxEvent) { const relatesTo = mxEvent.getContent()["m.relates_to"]; @@ -133,16 +133,16 @@ export default class EditMessageComposer extends React.Component { if (this._editorRef.isComposing(event)) { return; } - const action = getKeyBindingsManager().getAction(KeyBindingContext.MessageComposer, event); + const action = getKeyBindingsManager().getMessageComposerAction(event); switch (action) { - case KeyAction.Send: + case MessageComposerAction.Send: this._sendEdit(); event.preventDefault(); break; - case KeyAction.CancelEditing: + case MessageComposerAction.CancelEditing: this._cancelEdit(); break; - case KeyAction.EditPrevMessage: { + case MessageComposerAction.EditPrevMessage: { if (this._editorRef.isModified() || !this._editorRef.isCaretAtStart()) { return; } @@ -154,7 +154,7 @@ export default class EditMessageComposer extends React.Component { } break; } - case KeyAction.EditNextMessage: { + case MessageComposerAction.EditNextMessage: { if (this._editorRef.isModified() || !this._editorRef.isCaretAtEnd()) { return; } diff --git a/src/components/views/rooms/RoomSublist.tsx b/src/components/views/rooms/RoomSublist.tsx index c0919090b0..25e3a34f34 100644 --- a/src/components/views/rooms/RoomSublist.tsx +++ b/src/components/views/rooms/RoomSublist.tsx @@ -51,7 +51,7 @@ import { objectExcluding, objectHasDiff } from "../../../utils/objects"; import TemporaryTile from "./TemporaryTile"; import { ListNotificationState } from "../../../stores/notifications/ListNotificationState"; import IconizedContextMenu from "../context_menus/IconizedContextMenu"; -import { getKeyBindingsManager, KeyAction, KeyBindingContext } from "../../../KeyBindingsManager"; +import { getKeyBindingsManager, RoomListAction } from "../../../KeyBindingsManager"; const SHOW_N_BUTTON_HEIGHT = 28; // As defined by CSS const RESIZE_HANDLE_HEIGHT = 4; // As defined by CSS @@ -471,16 +471,16 @@ export default class RoomSublist extends React.Component { }; private onHeaderKeyDown = (ev: React.KeyboardEvent) => { - const action = getKeyBindingsManager().getAction(KeyBindingContext.RoomList, ev); + const action = getKeyBindingsManager().getRoomListAction(ev); switch (action) { - case KeyAction.RoomListCollapseSection: + case RoomListAction.CollapseSection: ev.stopPropagation(); if (this.state.isExpanded) { // Collapse the room sublist if it isn't already this.toggleCollapsed(); } break; - case KeyAction.RoomListExpandSection: { + case RoomListAction.ExpandSection: { ev.stopPropagation(); if (!this.state.isExpanded) { // Expand the room sublist if it isn't already diff --git a/src/components/views/rooms/SendMessageComposer.js b/src/components/views/rooms/SendMessageComposer.js index adfa38b56a..b5188b248b 100644 --- a/src/components/views/rooms/SendMessageComposer.js +++ b/src/components/views/rooms/SendMessageComposer.js @@ -46,7 +46,7 @@ import {CHAT_EFFECTS} from '../../../effects'; import CountlyAnalytics from "../../../CountlyAnalytics"; import {MatrixClientPeg} from "../../../MatrixClientPeg"; import EMOJI_REGEX from 'emojibase-regex'; -import {getKeyBindingsManager, KeyAction, KeyBindingContext} from '../../../KeyBindingsManager'; +import {getKeyBindingsManager, MessageComposerAction} from '../../../KeyBindingsManager'; function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) { const replyContent = ReplyThread.makeReplyMixIn(repliedToEvent); @@ -143,23 +143,23 @@ export default class SendMessageComposer extends React.Component { if (this._editorRef.isComposing(event)) { return; } - const action = getKeyBindingsManager().getAction(KeyBindingContext.MessageComposer, event); + const action = getKeyBindingsManager().getMessageComposerAction(event); switch (action) { - case KeyAction.Send: + case MessageComposerAction.Send: this._sendMessage(); event.preventDefault(); break; - case KeyAction.SelectPrevSendHistory: - case KeyAction.SelectNextSendHistory: { + case MessageComposerAction.SelectPrevSendHistory: + case MessageComposerAction.SelectNextSendHistory: { // Try select composer history - const selected = this.selectSendHistory(action === KeyAction.SelectPrevSendHistory); + const selected = this.selectSendHistory(action === MessageComposerAction.SelectPrevSendHistory); if (selected) { // We're selecting history, so prevent the key event from doing anything else event.preventDefault(); } break; } - case KeyAction.EditPrevMessage: + case MessageComposerAction.EditPrevMessage: // selection must be collapsed and caret at start if (this._editorRef.isSelectionCollapsed() && this._editorRef.isCaretAtStart()) { const editEvent = findEditableEvent(this.props.room, false); @@ -173,7 +173,7 @@ export default class SendMessageComposer extends React.Component { } } break; - case KeyAction.CancelEditing: + case MessageComposerAction.CancelEditing: dis.dispatch({ action: 'reply_to_event', event: null,