Split KeyAction into multiple enums
This gives some additional type safety and makes enum member usage more clear.
This commit is contained in:
parent
32ec8b7dc8
commit
601be50b71
8 changed files with 185 additions and 193 deletions
|
@ -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<IProps, IState> {
|
|||
_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<IProps, IState> {
|
|||
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<ToggleRightPanelPayload>({
|
||||
action: Action.ToggleRightPanel,
|
||||
|
@ -455,7 +455,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
handled = true;
|
||||
}
|
||||
break;
|
||||
case KeyAction.NavSelectPrevRoom:
|
||||
case NavigationAction.SelectPrevRoom:
|
||||
dis.dispatch<ViewRoomDeltaPayload>({
|
||||
action: Action.ViewRoomDelta,
|
||||
delta: -1,
|
||||
|
@ -463,7 +463,7 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
});
|
||||
handled = true;
|
||||
break;
|
||||
case KeyAction.NavSelectNextRoom:
|
||||
case NavigationAction.SelectNextRoom:
|
||||
dis.dispatch<ViewRoomDeltaPayload>({
|
||||
action: Action.ViewRoomDelta,
|
||||
delta: 1,
|
||||
|
@ -471,14 +471,14 @@ class LoggedInView extends React.Component<IProps, IState> {
|
|||
});
|
||||
handled = true;
|
||||
break;
|
||||
case KeyAction.NavSelectPrevUnreadRoom:
|
||||
case NavigationAction.SelectPrevUnreadRoom:
|
||||
dis.dispatch<ViewRoomDeltaPayload>({
|
||||
action: Action.ViewRoomDelta,
|
||||
delta: -1,
|
||||
unread: true,
|
||||
});
|
||||
break;
|
||||
case KeyAction.NavSelectNextUnreadRoom:
|
||||
case NavigationAction.SelectNextUnreadRoom:
|
||||
dis.dispatch<ViewRoomDeltaPayload>({
|
||||
action: Action.ViewRoomDelta,
|
||||
delta: 1,
|
||||
|
|
|
@ -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<IProps, IState> {
|
|||
};
|
||||
|
||||
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
|
||||
|
|
|
@ -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<IProps, IState> {
|
|||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue