Map keyboard shortcuts on windows (#526)
* Map keyboard shortcuts on windows * Fixed also saving commands * Fix keyboard shortcut for keyboard shortcuts * Fixed guide * Cmd -> Mod
This commit is contained in:
@ -19,6 +19,7 @@ import { insertImageFile } from './changes';
|
|||||||
import renderMark from './marks';
|
import renderMark from './marks';
|
||||||
import createRenderNode from './nodes';
|
import createRenderNode from './nodes';
|
||||||
import schema from './schema';
|
import schema from './schema';
|
||||||
|
import { isModKey } from './utils';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -136,7 +137,7 @@ class MarkdownEditor extends Component {
|
|||||||
|
|
||||||
// Handling of keyboard shortcuts within editor focus
|
// Handling of keyboard shortcuts within editor focus
|
||||||
onKeyDown = (ev: SyntheticKeyboardEvent, change: Change) => {
|
onKeyDown = (ev: SyntheticKeyboardEvent, change: Change) => {
|
||||||
if (!ev.metaKey) return;
|
if (!isModKey(ev)) return;
|
||||||
|
|
||||||
switch (ev.key) {
|
switch (ev.key) {
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { Change } from 'slate';
|
import { Change } from 'slate';
|
||||||
|
import { isModKey } from '../utils';
|
||||||
|
|
||||||
export default function KeyboardShortcuts() {
|
export default function KeyboardShortcuts() {
|
||||||
return {
|
return {
|
||||||
onKeyDown(ev: SyntheticKeyboardEvent, change: Change) {
|
onKeyDown(ev: SyntheticKeyboardEvent, change: Change) {
|
||||||
if (!ev.metaKey) return null;
|
if (!isModKey(ev)) return null;
|
||||||
|
|
||||||
switch (ev.key) {
|
switch (ev.key) {
|
||||||
case 'b':
|
case 'b':
|
||||||
|
11
app/components/Editor/utils.js
Normal file
11
app/components/Editor/utils.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// @flow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect Cmd or Ctrl by platform for keyboard shortcuts
|
||||||
|
*/
|
||||||
|
export function isModKey(event: SyntheticKeyboardEvent) {
|
||||||
|
const isMac =
|
||||||
|
typeof window !== 'undefined' &&
|
||||||
|
/Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
|
||||||
|
return isMac ? event.metaKey : event.ctrlKey;
|
||||||
|
}
|
@ -38,7 +38,7 @@ function KeyboardShortcuts() {
|
|||||||
<Label>Jump to dashboard</Label>
|
<Label>Jump to dashboard</Label>
|
||||||
|
|
||||||
<Keys>
|
<Keys>
|
||||||
<Key>⌘</Key> + <Key>/</Key>
|
<Key>?</Key>
|
||||||
</Keys>
|
</Keys>
|
||||||
<Label>Open this guide</Label>
|
<Label>Open this guide</Label>
|
||||||
</List>
|
</List>
|
||||||
|
Reference in New Issue
Block a user