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

Commit 08d24e2

Browse files
committed
Add a keyboard shortcut to toggle hidden event visibility when labs are enabled.
Notes: The keyboard shortcut is control (or cmd) shift h. Signed-off-by: Katarzyna Stachura <[email protected]>
1 parent 010cbad commit 08d24e2

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed

src/KeyBindingsDefaults.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import {
2222
NavigationAction,
2323
RoomAction,
2424
RoomListAction,
25+
LabsAction,
2526
} from "./KeyBindingsManager";
2627
import { isMac, Key } from "./Keyboard";
2728
import SettingsStore from "./settings/SettingsStore";
29+
import SdkConfig from "./SdkConfig";
2830

2931
const messageComposerBindings = (): KeyBinding<MessageComposerAction>[] => {
3032
const bindings: KeyBinding<MessageComposerAction>[] = [
@@ -411,10 +413,28 @@ const navigationBindings = (): KeyBinding<NavigationAction>[] => {
411413
];
412414
};
413415

416+
const labsBindings = (): KeyBinding<LabsAction>[] => {
417+
if (!SdkConfig.get()['showLabsSettings']) {
418+
return [];
419+
}
420+
421+
return [
422+
{
423+
action: LabsAction.ToggleHiddenEventVisibility,
424+
keyCombo: {
425+
key: Key.H,
426+
ctrlOrCmd: true,
427+
shiftKey: true,
428+
},
429+
},
430+
];
431+
};
432+
414433
export const defaultBindingsProvider: IKeyBindingsProvider = {
415434
getMessageComposerBindings: messageComposerBindings,
416435
getAutocompleteBindings: autocompleteBindings,
417436
getRoomListBindings: roomListBindings,
418437
getRoomBindings: roomBindings,
419438
getNavigationBindings: navigationBindings,
439+
getLabsBindings: labsBindings,
420440
};

src/KeyBindingsManager.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ export enum NavigationAction {
125125
SelectNextUnreadRoom = 'SelectNextUnreadRoom',
126126
}
127127

128+
/** Actions only available when labs are enabled */
129+
export enum LabsAction {
130+
/** Toggle visibility of hidden events */
131+
ToggleHiddenEventVisibility = 'ToggleHiddenEventVisibility',
132+
}
133+
128134
/**
129135
* Represent a key combination.
130136
*
@@ -213,6 +219,7 @@ export interface IKeyBindingsProvider {
213219
getRoomListBindings: KeyBindingGetter<RoomListAction>;
214220
getRoomBindings: KeyBindingGetter<RoomAction>;
215221
getNavigationBindings: KeyBindingGetter<NavigationAction>;
222+
getLabsBindings: KeyBindingGetter<LabsAction>;
216223
}
217224

218225
export class KeyBindingsManager {
@@ -264,6 +271,10 @@ export class KeyBindingsManager {
264271
getNavigationAction(ev: KeyboardEvent | React.KeyboardEvent): NavigationAction | undefined {
265272
return this.getAction(this.bindingsProviders.map(it => it.getNavigationBindings), ev);
266273
}
274+
275+
getLabsAction(ev: KeyboardEvent | React.KeyboardEvent): LabsAction | undefined {
276+
return this.getAction(this.bindingsProviders.map(it => it.getLabsBindings), ev);
277+
}
267278
}
268279

269280
const manager = new KeyBindingsManager();

src/accessibility/KeyboardShortcuts.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export enum Categories {
2424
ROOM_LIST = "Room List",
2525
ROOM = "Room",
2626
AUTOCOMPLETE = "Autocomplete",
27+
LABS = "Labs",
2728
}
2829

2930
export enum Modifiers {
@@ -276,6 +277,18 @@ export const shortcuts: Record<Categories, IShortcut[]> = {
276277
description: _td("Cancel autocomplete"),
277278
},
278279
],
280+
281+
// SdkConfig isn't initialized here, so add labs shortcuts unconditionally. The logic whether they should be visible
282+
// and enabled belongs in other places anyway.
283+
[Categories.LABS]: [
284+
{
285+
keybinds: [{
286+
modifiers: [CMD_OR_CTRL, Modifiers.SHIFT],
287+
key: Key.H,
288+
}],
289+
description: _td("Toggle visibility of hidden events"),
290+
},
291+
],
279292
};
280293

281294
export const registerShortcut = (category: Categories, defn: IShortcut) => {

src/components/structures/LoggedInView.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { fixupColorFonts } from '../../utils/FontManager';
2929
import dis from '../../dispatcher/dispatcher';
3030
import { IMatrixClientCreds } from '../../MatrixClientPeg';
3131
import SettingsStore from "../../settings/SettingsStore";
32+
import { SettingLevel } from "../../settings/SettingLevel";
3233
import ResizeHandle from '../views/elements/ResizeHandle';
3334
import { CollapseDistributor, Resizer } from '../../resizer';
3435
import MatrixClientContext from "../../contexts/MatrixClientContext";
@@ -47,7 +48,7 @@ import { IOOBData, IThreepidInvite } from "../../stores/ThreepidInviteStore";
4748
import Modal from "../../Modal";
4849
import { ICollapseConfig } from "../../resizer/distributors/collapse";
4950
import HostSignupContainer from '../views/host_signup/HostSignupContainer';
50-
import { getKeyBindingsManager, NavigationAction, RoomAction } from '../../KeyBindingsManager';
51+
import { getKeyBindingsManager, NavigationAction, RoomAction, LabsAction } from '../../KeyBindingsManager';
5152
import { IOpts } from "../../createRoom";
5253
import SpacePanel from "../views/spaces/SpacePanel";
5354
import { replaceableComponent } from "../../utils/replaceableComponent";
@@ -531,6 +532,33 @@ class LoggedInView extends React.Component<IProps, IState> {
531532
// if we do not have a handler for it, pass it to the platform which might
532533
handled = PlatformPeg.get().onKeyDown(ev);
533534
}
535+
536+
// Handle labs actions here, as they apply within the same scope
537+
if (!handled) {
538+
const labsAction = getKeyBindingsManager().getLabsAction(ev);
539+
switch (labsAction) {
540+
case LabsAction.ToggleHiddenEventVisibility: {
541+
const hiddenEventVisibility = SettingsStore.getValueAt(
542+
SettingLevel.DEVICE,
543+
'showHiddenEventsInTimeline',
544+
undefined,
545+
false,
546+
);
547+
SettingsStore.setValue(
548+
'showHiddenEventsInTimeline',
549+
undefined,
550+
SettingLevel.DEVICE,
551+
!hiddenEventVisibility,
552+
);
553+
handled = true;
554+
break;
555+
}
556+
default:
557+
// if we do not have a handler for it, pass it to the platform which might
558+
handled = PlatformPeg.get().onKeyDown(ev);
559+
}
560+
}
561+
534562
if (handled) {
535563
ev.stopPropagation();
536564
ev.preventDefault();

src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import React from "react";
2121
import { Categories, DIGITS, IShortcut, Modifiers, shortcuts } from "../../../../../accessibility/KeyboardShortcuts";
2222
import { isMac, Key } from "../../../../../Keyboard";
2323
import { _t, _td } from "../../../../../languageHandler";
24+
import SdkConfig from "../../../../../SdkConfig";
2425

2526
// TS: once languageHandler is TS we can probably inline this into the enum
2627
_td("Alt");
@@ -33,6 +34,7 @@ _td("Calls");
3334
_td("Composer");
3435
_td("Room List");
3536
_td("Autocomplete");
37+
_td("Labs");
3638

3739
const categoryOrder = [
3840
Categories.COMPOSER,
@@ -43,6 +45,11 @@ const categoryOrder = [
4345
Categories.CALLS,
4446
];
4547

48+
// Add the labs category if they're enabled
49+
if (SdkConfig.get()['showLabsSettings']) {
50+
categoryOrder.push(Categories.LABS);
51+
}
52+
4653
const modifierIcon: Record<string, string> = {
4754
[Modifiers.COMMAND]: "⌘",
4855
};

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@
14411441
"Composer": "Composer",
14421442
"Room List": "Room List",
14431443
"Autocomplete": "Autocomplete",
1444+
"Labs": "Labs",
14441445
"Page Up": "Page Up",
14451446
"Page Down": "Page Down",
14461447
"Esc": "Esc",
@@ -1449,7 +1450,6 @@
14491450
"End": "End",
14501451
"[number]": "[number]",
14511452
"Keyboard": "Keyboard",
1452-
"Labs": "Labs",
14531453
"Feeling experimental? Labs are the best way to get things early, test out new features and help shape them before they actually launch. <a>Learn more</a>.": "Feeling experimental? Labs are the best way to get things early, test out new features and help shape them before they actually launch. <a>Learn more</a>.",
14541454
"Ignored/Blocked": "Ignored/Blocked",
14551455
"Error adding ignored user/server": "Error adding ignored user/server",
@@ -3411,5 +3411,6 @@
34113411
"Open this settings tab": "Open this settings tab",
34123412
"Go to Home View": "Go to Home View",
34133413
"Move autocomplete selection up/down": "Move autocomplete selection up/down",
3414-
"Cancel autocomplete": "Cancel autocomplete"
3414+
"Cancel autocomplete": "Cancel autocomplete",
3415+
"Toggle visibility of hidden events": "Toggle visibility of hidden events"
34153416
}

0 commit comments

Comments
 (0)