add global keyboard shortcut for toggling docs

This handles the cases when the editor is not active and the docs pane
is not active and the terminal is not active.
This commit is contained in:
David Lechner
2021-01-27 16:33:03 -06:00
parent 1d7414bd83
commit eb2cf3c956
+23 -1
View File
@@ -8,6 +8,9 @@ import {
Classes,
Drawer,
FormGroup,
Hotkey,
Hotkeys,
HotkeysTarget,
Position,
Switch,
Tooltip,
@@ -17,7 +20,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { Action, Dispatch } from '../actions';
import { closeSettings, openAboutDialog } from '../actions/app';
import { setBoolean } from '../actions/settings';
import { setBoolean, toggleBoolean } from '../actions/settings';
import { RootState } from '../reducers';
import { pseudolocalize } from '../settings/i18n';
import {
@@ -47,10 +50,12 @@ type DispatchProps = {
onDarkModeChanged: (checked: boolean) => void;
onFlashCurrentProgramChanged: (checked: boolean) => void;
onAbout: () => void;
onToggleDocs: () => void;
};
type SettingsProps = StateProps & DispatchProps & WithI18nProps;
@HotkeysTarget
class SettingsDrawer extends React.PureComponent<SettingsProps> {
render(): JSX.Element {
const {
@@ -223,6 +228,22 @@ class SettingsDrawer extends React.PureComponent<SettingsProps> {
</Drawer>
);
}
renderHotkeys(): JSX.Element {
return (
<Hotkeys>
<Hotkey
combo="mod+d"
label={this.props.i18n.translate(
SettingsStringId.AppearanceDocumentationTooltip,
)}
global={true}
preventDefault={true}
onKeyDown={() => this.props.onToggleDocs()}
/>
</Hotkeys>
);
}
}
const mapStateToProps = (state: RootState): StateProps => ({
@@ -241,6 +262,7 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onFlashCurrentProgramChanged: (checked): Action =>
dispatch(setBoolean(SettingId.FlashCurrentProgram, checked)),
onAbout: (): Action => dispatch(openAboutDialog()),
onToggleDocs: (): Action => dispatch(toggleBoolean(SettingId.ShowDocs)),
});
export default connect(