mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
refs #226 Enables to use multiple key for shortcut
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user