Skip to content

Commit 6901088

Browse files
committed
update markdown mark hotkeys to use isHotkey
1 parent 420e779 commit 6901088

File tree

1 file changed

+11
-13
lines changed
  • src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor

1 file changed

+11
-13
lines changed

src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/keys.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Block, Text } from 'slate';
2-
import { isHotkey } from 'is-hotkey';
2+
import isHotkey from 'is-hotkey';
33

44
export default onKeyDown;
55

@@ -38,19 +38,17 @@ function onKeyDown(event, change) {
3838
.collapseToStartOf(newBlock);
3939
}
4040

41-
if (isHotkey(`mod+${event.key}`, event)) {
42-
const marks = {
43-
b: 'bold',
44-
i: 'italic',
45-
s: 'strikethrough',
46-
'`': 'code',
47-
};
41+
const marks = [
42+
[ 'b', 'bold' ],
43+
[ 'i', 'italic' ],
44+
[ 's', 'strikethrough' ],
45+
[ '`', 'code' ],
46+
];
4847

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

51-
if (mark) {
52-
event.preventDefault();
53-
return change.toggleMark(mark);
54-
}
50+
if (markName) {
51+
event.preventDefault();
52+
return change.toggleMark(markName);
5553
}
5654
};

0 commit comments

Comments
 (0)