update markdown mark hotkeys to use isHotkey

This commit is contained in:
Shawn Erquhart 2017-12-14 14:35:54 -08:00
parent 7c9c765c28
commit 78ad082021

View File

@ -1,5 +1,5 @@
import { Block, Text } from 'slate'; import { Block, Text } from 'slate';
import { isHotkey } from 'is-hotkey'; import isHotkey from 'is-hotkey';
export default onKeyDown; export default onKeyDown;
@ -38,19 +38,17 @@ function onKeyDown(event, change) {
.collapseToStartOf(newBlock); .collapseToStartOf(newBlock);
} }
if (isHotkey(`mod+${event.key}`, event)) { const marks = [
const marks = { [ 'b', 'bold' ],
b: 'bold', [ 'i', 'italic' ],
i: 'italic', [ 's', 'strikethrough' ],
s: 'strikethrough', [ '`', 'code' ],
'`': 'code', ];
};
const mark = marks[event.key]; const [ markKey, markName ] = marks.find(([ key ]) => isHotkey(`mod+${key}`, event)) || [];
if (mark) { if (markName) {
event.preventDefault(); event.preventDefault();
return change.toggleMark(mark); return change.toggleMark(markName);
}
} }
}; };