From cdb079dc814e1fa34f0f273b30786405387ac120 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 14 Jan 2017 18:44:53 +0900 Subject: [PATCH] refs #226 Enables to use multiple key for shortcut --- browser/components/MarkdownEditor.js | 14 +++++++++++++- browser/main/lib/ConfigManager.js | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index d31b30d4..b77c5bda 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -8,6 +8,10 @@ class MarkdownEditor extends React.Component { constructor (props) { super(props) + this.hotkey = props.config.hotkey + + this.keyPressed = [] + this.state = { status: 'PREVIEW', renderValue: props.value @@ -143,11 +147,18 @@ class MarkdownEditor extends React.Component { } handleKeyDown(e) { - if (this.state.status === 'CODE' && e.key == 'Escape') { + this.keyPressed[e.key] = true + let isNoteHandlerKey = (el) => { return this.keyPressed[el] } + if (this.state.status === 'CODE' && this.hotkey.noteHandlerKey.escapeFromEditor.every(isNoteHandlerKey)) { document.activeElement.blur() + this.hotkey.noteHandlerKey.escapeFromEditor.forEach((el) => {this.keyPressed[el] = false}) } } + handleKeyUp (e) { + this.keyPressed[e.key] = false + } + render () { let { className, value, config } = this.props @@ -167,6 +178,7 @@ class MarkdownEditor extends React.Component { onContextMenu={(e) => this.handleContextMenu(e)} tabIndex='-1' onKeyDown={(e) => this.handleKeyDown(e)} + onKeyUp={(e) => this.handleKeyUp(e)} >