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 <uwunyaa@outlook.com>
This commit is contained in:
UwUnyaa 2022-01-26 17:50:47 +01:00 committed by GitHub
parent 00912c0b50
commit debf4caade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 3 deletions

View file

@ -29,6 +29,7 @@ import { fixupColorFonts } from '../../utils/FontManager';
import dis from '../../dispatcher/dispatcher';
import { IMatrixClientCreds } from '../../MatrixClientPeg';
import SettingsStore from "../../settings/SettingsStore";
import { SettingLevel } from "../../settings/SettingLevel";
import ResizeHandle from '../views/elements/ResizeHandle';
import { CollapseDistributor, Resizer } from '../../resizer';
import MatrixClientContext from "../../contexts/MatrixClientContext";
@ -47,7 +48,7 @@ import { IOOBData, IThreepidInvite } from "../../stores/ThreepidInviteStore";
import Modal from "../../Modal";
import { ICollapseConfig } from "../../resizer/distributors/collapse";
import HostSignupContainer from '../views/host_signup/HostSignupContainer';
import { getKeyBindingsManager, NavigationAction, RoomAction } from '../../KeyBindingsManager';
import { getKeyBindingsManager, NavigationAction, RoomAction, LabsAction } from '../../KeyBindingsManager';
import { IOpts } from "../../createRoom";
import SpacePanel from "../views/spaces/SpacePanel";
import { replaceableComponent } from "../../utils/replaceableComponent";
@ -537,6 +538,33 @@ class LoggedInView extends React.Component<IProps, IState> {
// if we do not have a handler for it, pass it to the platform which might
handled = PlatformPeg.get().onKeyDown(ev);
}
// Handle labs actions here, as they apply within the same scope
if (!handled) {
const labsAction = getKeyBindingsManager().getLabsAction(ev);
switch (labsAction) {
case LabsAction.ToggleHiddenEventVisibility: {
const hiddenEventVisibility = SettingsStore.getValueAt(
SettingLevel.DEVICE,
'showHiddenEventsInTimeline',
undefined,
false,
);
SettingsStore.setValue(
'showHiddenEventsInTimeline',
undefined,
SettingLevel.DEVICE,
!hiddenEventVisibility,
);
handled = true;
break;
}
default:
// if we do not have a handler for it, pass it to the platform which might
handled = PlatformPeg.get().onKeyDown(ev);
}
}
if (handled) {
ev.stopPropagation();
ev.preventDefault();

View file

@ -25,6 +25,7 @@ import {
CATEGORIES,
CategoryName,
} from "../../../../../accessibility/KeyboardShortcuts";
import SdkConfig from "../../../../../SdkConfig";
import { isMac, Key } from "../../../../../Keyboard";
import { _t } from "../../../../../languageHandler";
@ -76,6 +77,10 @@ interface IKeyboardShortcutRowProps {
name: string;
}
// Filter out the labs section if labs aren't enabled.
const visibleCategories = Object.entries(CATEGORIES).filter(([categoryName]) =>
categoryName !== CategoryName.LABS || SdkConfig.get()['showLabsSettings']);
const KeyboardShortcutRow: React.FC<IKeyboardShortcutRowProps> = ({ name }) => {
return <div className="mx_KeyboardShortcut_shortcutRow">
{ KEYBOARD_SHORTCUTS[name].displayName }
@ -100,7 +105,7 @@ const KeyboardShortcutSection: React.FC<IKeyboardShortcutSectionProps> = ({ cate
const KeyboardUserSettingsTab: React.FC = () => {
return <div className="mx_SettingsTab mx_KeyboardUserSettingsTab">
<div className="mx_SettingsTab_heading">{ _t("Keyboard") }</div>
{ Object.entries(CATEGORIES).map(([categoryName, category]: [CategoryName, ICategory]) => {
{ visibleCategories.map(([categoryName, category]: [CategoryName, ICategory]) => {
return <KeyboardShortcutSection key={categoryName} categoryName={categoryName} category={category} />;
}) }
</div>;