Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7d08752

Browse files
committed
Make use of the KeyBindingManager in LeftPanel
LeftPanel was making key action decisions based on the forwarded event. Use the KeyBindingManager now. Signed-off-by: Clemens Zeidler <[email protected]>
1 parent 33e8edb commit 7d08752

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/components/structures/LeftPanel.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { UPDATE_EVENT } from "../../stores/AsyncStore";
3434
import ResizeNotifier from "../../utils/ResizeNotifier";
3535
import SettingsStore from "../../settings/SettingsStore";
3636
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../stores/room-list/RoomListStore";
37-
import {Key} from "../../Keyboard";
3837
import IndicatorScrollbar from "../structures/IndicatorScrollbar";
3938
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
4039
import { OwnProfileStore } from "../../stores/OwnProfileStore";
@@ -43,6 +42,7 @@ import LeftPanelWidget from "./LeftPanelWidget";
4342
import {replaceableComponent} from "../../utils/replaceableComponent";
4443
import {mediaFromMxc} from "../../customisations/Media";
4544
import SpaceStore, {UPDATE_SELECTED_SPACE} from "../../stores/SpaceStore";
45+
import { getKeyBindingsManager, RoomListAction } from "../../KeyBindingsManager";
4646

4747
interface IProps {
4848
isMinimized: boolean;
@@ -297,17 +297,18 @@ export default class LeftPanel extends React.Component<IProps, IState> {
297297
private onKeyDown = (ev: React.KeyboardEvent) => {
298298
if (!this.focusedElement) return;
299299

300-
switch (ev.key) {
301-
case Key.ARROW_UP:
302-
case Key.ARROW_DOWN:
300+
const action = getKeyBindingsManager().getRoomListAction(ev);
301+
switch (action) {
302+
case RoomListAction.NextRoom:
303+
case RoomListAction.PrevRoom:
303304
ev.stopPropagation();
304305
ev.preventDefault();
305-
this.onMoveFocus(ev.key === Key.ARROW_UP);
306+
this.onMoveFocus(action === RoomListAction.PrevRoom);
306307
break;
307308
}
308309
};
309310

310-
private onEnter = () => {
311+
private selectRoom = () => {
311312
const firstRoom = this.listContainerRef.current.querySelector<HTMLDivElement>(".mx_RoomTile");
312313
if (firstRoom) {
313314
firstRoom.click();
@@ -388,8 +389,8 @@ export default class LeftPanel extends React.Component<IProps, IState> {
388389
>
389390
<RoomSearch
390391
isMinimized={this.props.isMinimized}
391-
onVerticalArrow={this.onKeyDown}
392-
onEnter={this.onEnter}
392+
onKeyDown={this.onKeyDown}
393+
onSelectRoom={this.selectRoom}
393394
/>
394395
<AccessibleTooltipButton
395396
className={classNames("mx_LeftPanel_exploreButton", {

src/components/structures/RoomSearch.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ import SpaceStore, {UPDATE_SELECTED_SPACE} from "../../stores/SpaceStore";
3030

3131
interface IProps {
3232
isMinimized: boolean;
33-
onVerticalArrow(ev: React.KeyboardEvent): void;
34-
onEnter(ev: React.KeyboardEvent): boolean;
33+
onKeyDown(ev: React.KeyboardEvent): void;
34+
/**
35+
* @returns true if a room has been selected and the search field should be cleared
36+
*/
37+
onSelectRoom(): boolean;
3538
}
3639

3740
interface IState {
@@ -120,10 +123,11 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
120123
break;
121124
case RoomListAction.NextRoom:
122125
case RoomListAction.PrevRoom:
123-
this.props.onVerticalArrow(ev);
126+
// we don't handle these actions here put pass the event on to the interested party (LeftPanel)
127+
this.props.onKeyDown(ev);
124128
break;
125129
case RoomListAction.SelectRoom: {
126-
const shouldClear = this.props.onEnter(ev);
130+
const shouldClear = this.props.onSelectRoom();
127131
if (shouldClear) {
128132
// wrap in set immediate to delay it so that we don't clear the filter & then change room
129133
setImmediate(() => {

0 commit comments

Comments
 (0)