1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

refs #226 Enables to use multiple key for shortcut

This commit is contained in:
asmsuechan
2017-01-14 18:44:53 +09:00
parent 2ac0d93caf
commit cdb079dc81
2 changed files with 17 additions and 2 deletions

View File

@@ -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)}
>
<CodeEditor styleName='codeEditor'
ref='code'

View File

@@ -16,7 +16,10 @@ export const DEFAULT_CONFIG = {
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
hotkey: {
toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S',
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E',
noteHandlerKey: {
escapeFromEditor: ['Control', 'e']
}
},
ui: {
theme: 'default',