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

Commit df55816

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 582a1b0 commit df55816

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

src/KeyBindingsDefaults.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
NavigationAction,
2323
RoomAction,
2424
RoomListAction,
25+
LabsAction,
2526
} from "./KeyBindingsManager";
2627
import { isMac, Key } from "./Keyboard";
2728
import SettingsStore from "./settings/SettingsStore";
@@ -411,10 +412,24 @@ const navigationBindings = (): KeyBinding<NavigationAction>[] => {
411412
];
412413
};
413414

415+
const labsBindings = (): KeyBinding<LabsAction>[] => {
416+
return [
417+
{
418+
action: LabsAction.ToggleHiddenEventVisibility,
419+
keyCombo: {
420+
key: Key.H,
421+
ctrlOrCmd: true,
422+
shiftKey: true,
423+
},
424+
},
425+
];
426+
};
427+
414428
export const defaultBindingsProvider: IKeyBindingsProvider = {
415429
getMessageComposerBindings: messageComposerBindings,
416430
getAutocompleteBindings: autocompleteBindings,
417431
getRoomListBindings: roomListBindings,
418432
getRoomBindings: roomBindings,
419433
getNavigationBindings: navigationBindings,
434+
getLabsBindings: labsBindings,
420435
};

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616

1717
import { _td } from "../languageHandler";
1818
import { isMac, Key } from "../Keyboard";
19+
import SdkConfig from "../SdkConfig";
1920

2021
export enum Categories {
2122
NAVIGATION = "Navigation",
@@ -24,6 +25,7 @@ export enum Categories {
2425
ROOM_LIST = "Room List",
2526
ROOM = "Room",
2627
AUTOCOMPLETE = "Autocomplete",
28+
LABS = "Labs",
2729
}
2830

2931
export enum Modifiers {
@@ -276,8 +278,22 @@ export const shortcuts: Record<Categories, IShortcut[]> = {
276278
description: _td("Cancel autocomplete"),
277279
},
278280
],
281+
282+
// Intentionally left blank, as bindings should be only added when the feature is enabled
283+
[Categories.LABS]: [],
279284
};
280285

286+
// Add this short only if labs are enabled, as the feature is only exposed there.
287+
if (SdkConfig.get()['showLabsSettings']) {
288+
shortcuts[Categories.LABS].push({
289+
keybinds: [{
290+
modifiers: [CMD_OR_CTRL, Modifiers.SHIFT],
291+
key: Key.H,
292+
}],
293+
description: _td("Toggle visibility of hidden events"),
294+
});
295+
}
296+
281297
export const registerShortcut = (category: Categories, defn: IShortcut) => {
282298
shortcuts[category].push(defn);
283299
};

src/components/structures/LoggedInView.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import classNames from 'classnames';
2222
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
2323
import { IUsageLimit } from 'matrix-js-sdk/src/@types/partials';
2424

25+
import SdkConfig from "../../SdkConfig";
2526
import { Key } from '../../Keyboard';
2627
import PageTypes from '../../PageTypes';
2728
import MediaDeviceHandler from '../../MediaDeviceHandler';
2829
import { fixupColorFonts } from '../../utils/FontManager';
2930
import dis from '../../dispatcher/dispatcher';
3031
import { IMatrixClientCreds } from '../../MatrixClientPeg';
3132
import SettingsStore from "../../settings/SettingsStore";
33+
import { SettingLevel } from "../../settings/SettingLevel";
3234
import ResizeHandle from '../views/elements/ResizeHandle';
3335
import { CollapseDistributor, Resizer } from '../../resizer';
3436
import MatrixClientContext from "../../contexts/MatrixClientContext";
@@ -47,7 +49,7 @@ import { IOOBData, IThreepidInvite } from "../../stores/ThreepidInviteStore";
4749
import Modal from "../../Modal";
4850
import { ICollapseConfig } from "../../resizer/distributors/collapse";
4951
import HostSignupContainer from '../views/host_signup/HostSignupContainer';
50-
import { getKeyBindingsManager, NavigationAction, RoomAction } from '../../KeyBindingsManager';
52+
import { getKeyBindingsManager, NavigationAction, RoomAction, LabsAction } from '../../KeyBindingsManager';
5153
import { IOpts } from "../../createRoom";
5254
import SpacePanel from "../views/spaces/SpacePanel";
5355
import { replaceableComponent } from "../../utils/replaceableComponent";
@@ -531,6 +533,33 @@ class LoggedInView extends React.Component<IProps, IState> {
531533
// if we do not have a handler for it, pass it to the platform which might
532534
handled = PlatformPeg.get().onKeyDown(ev);
533535
}
536+
537+
// Handle labs actions here, as they apply within the same scope
538+
if (SdkConfig.get()['showLabsSettings'] && !handled) {
539+
const labsAction = getKeyBindingsManager().getLabsAction(ev);
540+
switch (labsAction) {
541+
case LabsAction.ToggleHiddenEventVisibility: {
542+
const hiddenEventVisibility = SettingsStore.getValueAt(
543+
SettingLevel.DEVICE,
544+
'showHiddenEventsInTimeline',
545+
undefined,
546+
false,
547+
);
548+
SettingsStore.setValue(
549+
'showHiddenEventsInTimeline',
550+
undefined,
551+
SettingLevel.DEVICE,
552+
!hiddenEventVisibility,
553+
);
554+
handled = true;
555+
break;
556+
}
557+
default:
558+
// if we do not have a handler for it, pass it to the platform which might
559+
handled = PlatformPeg.get().onKeyDown(ev);
560+
}
561+
}
562+
534563
if (handled) {
535564
ev.stopPropagation();
536565
ev.preventDefault();

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3408,5 +3408,6 @@
34083408
"Open this settings tab": "Open this settings tab",
34093409
"Go to Home View": "Go to Home View",
34103410
"Move autocomplete selection up/down": "Move autocomplete selection up/down",
3411-
"Cancel autocomplete": "Cancel autocomplete"
3411+
"Cancel autocomplete": "Cancel autocomplete",
3412+
"Toggle visibility of hidden events": "Toggle visibility of hidden events"
34123413
}

0 commit comments

Comments
 (0)