Keybinding code unification #3 (#7850)

This commit is contained in:
Šimon Brandner
2022-02-23 10:12:04 +01:00
committed by GitHub
parent b0737b6e31
commit 93a9af7b3a
9 changed files with 214 additions and 81 deletions

View File

@@ -23,7 +23,7 @@ import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
import { IUsageLimit } from 'matrix-js-sdk/src/@types/partials';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Key } from '../../Keyboard';
import { isOnlyCtrlOrCmdKeyEvent, Key } from '../../Keyboard';
import PageTypes from '../../PageTypes';
import MediaDeviceHandler from '../../MediaDeviceHandler';
import { fixupColorFonts } from '../../utils/FontManager';
@@ -73,6 +73,7 @@ import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
import RightPanelStore from '../../stores/right-panel/RightPanelStore';
import { TimelineRenderingType } from "../../contexts/RoomContext";
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
import { SwitchSpacePayload } from "../../dispatcher/payloads/SwitchSpacePayload";
// 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.
@@ -535,9 +536,14 @@ class LoggedInView extends React.Component<IProps, IState> {
unread: true,
});
break;
default:
// if we do not have a handler for it, pass it to the platform which might
handled = PlatformPeg.get().onKeyDown(ev);
case KeyBindingAction.PreviousVisitedRoomOrCommunity:
PlatformPeg.get().navigateForwardBack(true);
handled = true;
break;
case KeyBindingAction.NextVisitedRoomOrCommunity:
PlatformPeg.get().navigateForwardBack(false);
handled = true;
break;
}
// Handle labs actions here, as they apply within the same scope
@@ -560,12 +566,24 @@ class LoggedInView extends React.Component<IProps, IState> {
handled = true;
break;
}
default:
// if we do not have a handler for it, pass it to the platform which might
handled = PlatformPeg.get().onKeyDown(ev);
}
}
if (
!handled &&
PlatformPeg.get().overrideBrowserShortcuts() &&
SpaceStore.spacesEnabled &&
ev.code.startsWith("Digit") &&
ev.code !== "Digit0" && // this is the shortcut for reset zoom, don't override it
isOnlyCtrlOrCmdKeyEvent(ev)
) {
dis.dispatch<SwitchSpacePayload>({
action: Action.SwitchSpace,
num: ev.code.slice(5), // Cut off the first 5 characters - "Digit"
});
handled = true;
}
if (handled) {
ev.stopPropagation();
ev.preventDefault();

View File

@@ -29,7 +29,6 @@ import { _t, _td } from '../../../languageHandler';
import VideoFeed from './VideoFeed';
import RoomAvatar from "../avatars/RoomAvatar";
import AccessibleButton from '../elements/AccessibleButton';
import { isOnlyCtrlOrCmdKeyEvent, Key } from '../../../Keyboard';
import { avatarUrlForMember } from '../../../Avatar';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import DesktopCapturerSourcePicker from "../elements/DesktopCapturerSourcePicker";
@@ -38,6 +37,8 @@ import CallViewSidebar from './CallViewSidebar';
import CallViewHeader from './CallView/CallViewHeader';
import CallViewButtons from "./CallView/CallViewButtons";
import PlatformPeg from "../../../PlatformPeg";
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
interface IProps {
// The call for us to display
@@ -293,25 +294,21 @@ export default class CallView extends React.Component<IProps, IState> {
// CallHandler would probably be a better place for this
private onNativeKeyDown = (ev): void => {
let handled = false;
const ctrlCmdOnly = isOnlyCtrlOrCmdKeyEvent(ev);
switch (ev.key) {
case Key.D:
if (ctrlCmdOnly) {
this.onMicMuteClick();
// show the controls to give feedback
this.buttonsRef.current?.showControls();
handled = true;
}
const callAction = getKeyBindingsManager().getCallAction(ev);
switch (callAction) {
case KeyBindingAction.ToggleMicInCall:
this.onMicMuteClick();
// show the controls to give feedback
this.buttonsRef.current?.showControls();
handled = true;
break;
case Key.E:
if (ctrlCmdOnly) {
this.onVidMuteClick();
// show the controls to give feedback
this.buttonsRef.current?.showControls();
handled = true;
}
case KeyBindingAction.ToggleWebcamInCall:
this.onVidMuteClick();
// show the controls to give feedback
this.buttonsRef.current?.showControls();
handled = true;
break;
}