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

Commit

Permalink
Merge pull request #5253 from miterion/develop
Browse files Browse the repository at this point in the history
Add keyboard shortcut to close the current conversation
  • Loading branch information
turt2live authored Nov 18, 2020
2 parents 11fb081 + 3fd13b8 commit e4c7ab5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ export class ModalManager {
return this.appendDialogAsync<T>(...rest);
}

public closeCurrentModal(reason: string) {
const modal = this.getCurrentModal();
if (!modal) {
return;
}
modal.closeReason = reason;
modal.close();
}

private buildModal<T extends any[]>(
prom: Promise<React.ComponentType>,
props?: IProps<T>,
Expand Down
6 changes: 6 additions & 0 deletions src/accessibility/KeyboardShortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ const shortcuts: Record<Categories, IShortcut[]> = {
key: Key.SLASH,
}],
description: _td("Toggle this dialog"),
}, {
keybinds: [{
modifiers: [CMD_OR_CTRL, Modifiers.ALT],
key: Key.H,
}],
description: _td("Go to Home View"),
},
],

Expand Down
14 changes: 13 additions & 1 deletion src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as PropTypes from 'prop-types';
import { MatrixClient } from 'matrix-js-sdk/src/client';
import { DragDropContext } from 'react-beautiful-dnd';

import {Key, isOnlyCtrlOrCmdKeyEvent, isOnlyCtrlOrCmdIgnoreShiftKeyEvent} from '../../Keyboard';
import {Key, isOnlyCtrlOrCmdKeyEvent, isOnlyCtrlOrCmdIgnoreShiftKeyEvent, isMac} from '../../Keyboard';
import PageTypes from '../../PageTypes';
import CallMediaHandler from '../../CallMediaHandler';
import { fixupColorFonts } from '../../utils/FontManager';
Expand Down Expand Up @@ -52,6 +52,7 @@ import RoomListStore from "../../stores/room-list/RoomListStore";
import NonUrgentToastContainer from "./NonUrgentToastContainer";
import { ToggleRightPanelPayload } from "../../dispatcher/payloads/ToggleRightPanelPayload";
import { IThreepidInvite } from "../../stores/ThreepidInviteStore";
import Modal from "../../Modal";
import { ICollapseConfig } from "../../resizer/distributors/collapse";

// We need to fetch each pinned message individually (if we don't already have it)
Expand Down Expand Up @@ -392,6 +393,7 @@ class LoggedInView extends React.Component<IProps, IState> {
const ctrlCmdOnly = isOnlyCtrlOrCmdKeyEvent(ev);
const hasModifier = ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey;
const isModifier = ev.key === Key.ALT || ev.key === Key.CONTROL || ev.key === Key.META || ev.key === Key.SHIFT;
const modKey = isMac ? ev.metaKey : ev.ctrlKey;

switch (ev.key) {
case Key.PAGE_UP:
Expand Down Expand Up @@ -436,6 +438,16 @@ class LoggedInView extends React.Component<IProps, IState> {
}
break;

case Key.H:
if (ev.altKey && modKey) {
dis.dispatch({
action: 'view_home_page',
});
Modal.closeCurrentModal("homeKeyboardShortcut");
handled = true;
}
break;

case Key.ARROW_UP:
case Key.ARROW_DOWN:
if (ev.altKey && !ev.ctrlKey && !ev.metaKey) {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,7 @@
"Activate selected button": "Activate selected button",
"Toggle right panel": "Toggle right panel",
"Toggle this dialog": "Toggle this dialog",
"Go to Home View": "Go to Home View",
"Move autocomplete selection up/down": "Move autocomplete selection up/down",
"Cancel autocomplete": "Cancel autocomplete",
"Page Up": "Page Up",
Expand Down

0 comments on commit e4c7ab5

Please sign in to comment.