From 6901088b349cd53d50911e6d989bba75931501c1 Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Thu, 14 Dec 2017 14:35:54 -0800 Subject: [PATCH] update markdown mark hotkeys to use isHotkey --- .../MarkdownControl/VisualEditor/keys.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/keys.js b/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/keys.js index 1868bd48da69..05a790d0c5ce 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/keys.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/keys.js @@ -1,5 +1,5 @@ import { Block, Text } from 'slate'; -import { isHotkey } from 'is-hotkey'; +import isHotkey from 'is-hotkey'; export default onKeyDown; @@ -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); } };