fixed shortcuts for macs

This commit is contained in:
Philip Molares 2020-08-26 22:05:21 +02:00 committed by mrdrogdrog
parent 9439855b08
commit 36af0dc841
2 changed files with 8 additions and 10 deletions

View file

@ -4,13 +4,14 @@ import { Trans } from 'react-i18next'
import { isMac } from '../../utils' import { isMac } from '../../utils'
export const Shortcut: React.FC = () => { export const Shortcut: React.FC = () => {
const modifierKey = isMac ? <kbd>Cmd</kbd> : <kbd>Ctrl</kbd> const modifierKey = isMac ? <kbd></kbd> : <kbd>Ctrl</kbd>
const altKey = isMac ? <kbd></kbd> : <kbd>Alt</kbd>
const shortcutMap: {[category: string]: { [functionName: string]: JSX.Element[] }} = { const shortcutMap: {[category: string]: { [functionName: string]: JSX.Element[] }} = {
'View Mode': { 'View Mode': {
'editor.help.shortcuts.view': [modifierKey, <> + </>, <kbd>Alt</kbd>, <> + </>, <kbd>V</kbd>], 'editor.help.shortcuts.view': [<kbd>Ctrl</kbd>, <> + </>, altKey, <> + </>, <kbd>V</kbd>],
'editor.help.shortcuts.both': [modifierKey, <> + </>, <kbd>Alt</kbd>, <> + </>, <kbd>B</kbd>], 'editor.help.shortcuts.both': [<kbd>Ctrl</kbd>, <> + </>, altKey, <> + </>, <kbd>B</kbd>],
'editor.help.shortcuts.edit': [modifierKey, <> + </>, <kbd>Alt</kbd>, <> + </>, <kbd>E</kbd>] 'editor.help.shortcuts.edit': [<kbd>Ctrl</kbd>, <> + </>, altKey, <> + </>, <kbd>E</kbd>]
}, },
Editor: { Editor: {
'editor.help.shortcuts.bold': [modifierKey, <> + </>, <kbd>B</kbd>], 'editor.help.shortcuts.bold': [modifierKey, <> + </>, <kbd>B</kbd>],

View file

@ -1,19 +1,16 @@
import { setEditorMode } from '../../../redux/editor/methods' import { setEditorMode } from '../../../redux/editor/methods'
import { EditorMode } from '../app-bar/editor-view-mode' import { EditorMode } from '../app-bar/editor-view-mode'
import { isMac } from '../utils'
export const shortcutHandler = (event: KeyboardEvent): void => { export const shortcutHandler = (event: KeyboardEvent): void => {
const modifierKey = isMac ? event.metaKey : event.ctrlKey if (event.ctrlKey && event.altKey && event.key === 'b') {
if (modifierKey && event.altKey && event.key === 'b') {
setEditorMode(EditorMode.BOTH) setEditorMode(EditorMode.BOTH)
} }
if (modifierKey && event.altKey && event.key === 'v') { if (event.ctrlKey && event.altKey && event.key === 'v') {
setEditorMode(EditorMode.PREVIEW) setEditorMode(EditorMode.PREVIEW)
} }
if (modifierKey && event.altKey && event.key === 'e') { if (event.ctrlKey && event.altKey && event.key === 'e') {
setEditorMode(EditorMode.EDITOR) setEditorMode(EditorMode.EDITOR)
} }
} }