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

Commit debf4ca

Browse files
authored
Add a keyboard shortcut to toggle hidden event visibility when labs are enabled. (#7584)
Notes: The keyboard shortcut is control (or cmd) shift h. Signed-off-by: Katarzyna Stachura <[email protected]>
1 parent 00912c0 commit debf4ca

File tree

6 files changed

+82
-3
lines changed

6 files changed

+82
-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

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

408422
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";
@@ -537,6 +538,33 @@ class LoggedInView extends React.Component<IProps, IState> {
537538
// if we do not have a handler for it, pass it to the platform which might
538539
handled = PlatformPeg.get().onKeyDown(ev);
539540
}
541+
542+
// Handle labs actions here, as they apply within the same scope
543+
if (!handled) {
544+
const labsAction = getKeyBindingsManager().getLabsAction(ev);
545+
switch (labsAction) {
546+
case LabsAction.ToggleHiddenEventVisibility: {
547+
const hiddenEventVisibility = SettingsStore.getValueAt(
548+
SettingLevel.DEVICE,
549+
'showHiddenEventsInTimeline',
550+
undefined,
551+
false,
552+
);
553+
SettingsStore.setValue(
554+
'showHiddenEventsInTimeline',
555+
undefined,
556+
SettingLevel.DEVICE,
557+
!hiddenEventVisibility,
558+
);
559+
handled = true;
560+
break;
561+
}
562+
default:
563+
// if we do not have a handler for it, pass it to the platform which might
564+
handled = PlatformPeg.get().onKeyDown(ev);
565+
}
566+
}
567+
540568
if (handled) {
541569
ev.stopPropagation();
542570
ev.preventDefault();

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

Lines changed: 6 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,10 @@ interface IKeyboardShortcutRowProps {
7677
name: string;
7778
}
7879

80+
// Filter out the labs section if labs aren't enabled.
81+
const visibleCategories = Object.entries(CATEGORIES).filter(([categoryName]) =>
82+
categoryName !== CategoryName.LABS || SdkConfig.get()['showLabsSettings']);
83+
7984
const KeyboardShortcutRow: React.FC<IKeyboardShortcutRowProps> = ({ name }) => {
8085
return <div className="mx_KeyboardShortcut_shortcutRow">
8186
{ KEYBOARD_SHORTCUTS[name].displayName }
@@ -100,7 +105,7 @@ const KeyboardShortcutSection: React.FC<IKeyboardShortcutSectionProps> = ({ cate
100105
const KeyboardUserSettingsTab: React.FC = () => {
101106
return <div className="mx_SettingsTab mx_KeyboardUserSettingsTab">
102107
<div className="mx_SettingsTab_heading">{ _t("Keyboard") }</div>
103-
{ Object.entries(CATEGORIES).map(([categoryName, category]: [CategoryName, ICategory]) => {
108+
{ visibleCategories.map(([categoryName, category]: [CategoryName, ICategory]) => {
104109
return <KeyboardShortcutSection key={categoryName} categoryName={categoryName} category={category} />;
105110
}) }
106111
</div>;

src/i18n/strings/en_EN.json

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

0 commit comments

Comments
 (0)