1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Change to use Object.assign by checking keyPressed and remove unnecessary processing

This commit is contained in:
asmsuechan
2017-01-20 19:15:31 +09:00
parent ec6de1b91b
commit de19c51061

View File

@@ -146,23 +146,21 @@ class MarkdownEditor extends React.Component {
}
handleKeyDown(e) {
let newKeyPressed = this.state.keyPressed
newKeyPressed[e.key] = true
this.setState({keyPressed: newKeyPressed})
const keyPressed = Object.assign(this.state.keyPressed, {
[e.key]: true
})
this.setState({ keyPressed })
let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] }
if (this.state.status === 'CODE' && this.hotkey.noteHandlerKey.escapeFromEditor.every(isNoteHandlerKey)) {
document.activeElement.blur()
this.hotkey.noteHandlerKey.escapeFromEditor.forEach((el) => {
newKeyPressed[e.key] = false
this.setState({keyPressed: newKeyPressed})
})
}
}
handleKeyUp (e) {
let newKeyPressed = this.state.keyPressed
newKeyPressed[e.key] = false
this.setState({keyPressed: newKeyPressed})
const keyPressed = Object.assign(this.state.keyPressed, {
[e.key]: false
})
this.setState({ keyPressed })
}
render () {