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

Commit b5cc833

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 4540cf5 commit b5cc833

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export enum CategoryName {
3131
ROOM_LIST = "Room List",
3232
ROOM = "Room",
3333
AUTOCOMPLETE = "Autocomplete",
34+
LABS = "Labs",
3435
}
3536

3637
// Meta-key representing the digits [0-9] often found at the top of standard keyboard layouts
@@ -125,6 +126,11 @@ export const CATEGORIES: Record<CategoryName, ICategory> = {
125126
"KeyBinding.nextOptionInAutoComplete",
126127
"KeyBinding.previousOptionInAutoComplete",
127128
],
129+
}, [CategoryName.LABS]: {
130+
categoryLabel: _td("Labs"),
131+
settingNames: [
132+
"KeyBinding.toggleHiddenEventVisibility",
133+
],
128134
},
129135
};
130136

@@ -402,6 +408,14 @@ export const KEYBOARD_SHORTCUTS: { [setting: string]: ISetting } = {
402408
},
403409
displayName: _td("Toggle space panel"),
404410
},
411+
"KeyBinding.toggleHiddenEventVisibility": {
412+
default: {
413+
ctrlOrCmdKey: true,
414+
shiftKey: true,
415+
key: Key.H,
416+
},
417+
displayName: _td("Toggle hidden event visibility"),
418+
},
405419
};
406420

407421
export const registerShortcut = (shortcutName: string, categoryName: CategoryName, shortcut: ISetting): void => {

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
CATEGORIES,
2626
CategoryName,
2727
} from "../../../../../accessibility/KeyboardShortcuts";
28+
import SdkConfig from "../../../../../SdkConfig";
2829
import { isMac, Key } from "../../../../../Keyboard";
2930
import { _t } from "../../../../../languageHandler";
3031

@@ -76,6 +77,12 @@ interface IKeyboardShortcutRowProps {
7677
name: string;
7778
}
7879

80+
// Filter out the labs section if labs aren't enabled.
81+
const visibleCategories = SdkConfig.get()['showLabsSettings']
82+
? Object.entries(CATEGORIES)
83+
: Object.entries(CATEGORIES)
84+
.filter(([categoryName]) => categoryName !== CategoryName.LABS);
85+
7986
const KeyboardShortcutRow: React.FC<IKeyboardShortcutRowProps> = ({ name }) => {
8087
return <div className="mx_KeyboardShortcut_shortcutRow">
8188
{ KEYBOARD_SHORTCUTS[name].displayName }
@@ -100,7 +107,7 @@ const KeyboardShortcutSection: React.FC<IKeyboardShortcutSectionProps> = ({ cate
100107
const KeyboardUserSettingsTab: React.FC = () => {
101108
return <div className="mx_SettingsTab mx_KeyboardUserSettingsTab">
102109
<div className="mx_SettingsTab_heading">{ _t("Keyboard") }</div>
103-
{ Object.entries(CATEGORIES).map(([categoryName, category]: [CategoryName, ICategory]) => {
110+
{ visibleCategories.map(([categoryName, category]: [CategoryName, ICategory]) => {
104111
return <KeyboardShortcutSection key={categoryName} categoryName={categoryName} category={category} />;
105112
}) }
106113
</div>;

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3414,5 +3414,6 @@
34143414
"Cancel autocomplete": "Cancel autocomplete",
34153415
"Next autocomplete suggestion": "Next autocomplete suggestion",
34163416
"Previous autocomplete suggestion": "Previous autocomplete suggestion",
3417-
"Toggle space panel": "Toggle space panel"
3417+
"Toggle space panel": "Toggle space panel",
3418+
"Toggle hidden event visibility": "Toggle hidden event visibility"
34183419
}

0 commit comments

Comments
 (0)