Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class MarkdownEditor extends React.Component {
constructor (props) {
super(props)

this.escapeFromEditor = ['Control', 'w']
// char codes for ctrl + w
this.escapeFromEditor = [17, 87]

this.supportMdSelectionBold = ['Control', ':']
// ctrl + shift + ;
this.supportMdSelectionBold = [16, 17, 186]

this.state = {
status: 'PREVIEW',
renderValue: props.value,
keyPressed: {},
keyPressed: new Set(),
isLocked: false
}

Expand Down Expand Up @@ -87,7 +89,7 @@ class MarkdownEditor extends React.Component {

handleBlur (e) {
if (this.state.isLocked) return
this.setState({ keyPressed: [] })
this.setState({ keyPressed: new Set() })
let { config } = this.props
if (config.editor.switchPreview === 'BLUR') {
let cursorPosition = this.refs.code.editor.getCursor()
Expand Down Expand Up @@ -161,15 +163,16 @@ class MarkdownEditor extends React.Component {

handleKeyDown (e) {
if (this.state.status !== 'CODE') return false
const keyPressed = Object.assign(this.state.keyPressed, {
[e.key]: true
})
const keyPressed = this.state.keyPressed
keyPressed.add(e.keyCode)
this.setState({ keyPressed })
let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] }
if (!this.state.isLocked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
let isNoteHandlerKey = (el) => { return keyPressed.has(el) }
if (keyPressed.size === this.escapeFromEditor.length &&
!this.state.isLocked && this.state.status === 'CODE' &&
this.escapeFromEditor.every(isNoteHandlerKey)) {
document.activeElement.blur()
}
if (this.supportMdSelectionBold.every(isNoteHandlerKey)) {
if (keyPressed.size === this.supportMdSelectionBold.length && this.supportMdSelectionBold.every(isNoteHandlerKey)) {
this.addMdAroundWord('**')
}
}
Expand All @@ -190,9 +193,8 @@ class MarkdownEditor extends React.Component {
}

handleKeyUp (e) {
const keyPressed = Object.assign(this.state.keyPressed, {
[e.key]: false
})
const keyPressed = this.state.keyPressed
keyPressed.delete(e.keyCode)
this.setState({ keyPressed })
}

Expand Down