Skip to content

Commit

Permalink
update markdown mark hotkeys to use isHotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Dec 14, 2017
1 parent 420e779 commit 6901088
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Block, Text } from 'slate';
import { isHotkey } from 'is-hotkey';
import isHotkey from 'is-hotkey';

export default onKeyDown;

Expand Down Expand Up @@ -38,19 +38,17 @@ function onKeyDown(event, change) {
.collapseToStartOf(newBlock);
}

if (isHotkey(`mod+${event.key}`, event)) {
const marks = {
b: 'bold',
i: 'italic',
s: 'strikethrough',
'`': 'code',
};
const marks = [
[ 'b', 'bold' ],
[ 'i', 'italic' ],
[ 's', 'strikethrough' ],
[ '`', 'code' ],
];

const mark = marks[event.key];
const [ markKey, markName ] = marks.find(([ key ]) => isHotkey(`mod+${key}`, event)) || [];

if (mark) {
event.preventDefault();
return change.toggleMark(mark);
}
if (markName) {
event.preventDefault();
return change.toggleMark(markName);
}
};

0 comments on commit 6901088

Please sign in to comment.