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

Change the order of focus and emit 'editor:lock'

This commit is contained in:
asmsuechan
2017-02-11 18:12:45 +09:00
parent 672d409bf2
commit e9525fae22
2 changed files with 14 additions and 5 deletions

View File

@@ -74,9 +74,11 @@ class MarkdownEditor extends React.Component {
}, () => { }, () => {
if (newStatus === 'CODE') { if (newStatus === 'CODE') {
this.refs.code.focus() this.refs.code.focus()
eventEmitter.emit('topbar:lock')
} else { } else {
this.refs.code.blur() this.refs.code.blur()
this.refs.preview.focus() this.refs.preview.focus()
eventEmitter.emit('topbar:lock')
} }
}) })
} }
@@ -91,9 +93,9 @@ class MarkdownEditor extends React.Component {
this.setState({ this.setState({
status: 'PREVIEW' status: 'PREVIEW'
}, () => { }, () => {
eventEmitter.emit('topbar:lock')
this.refs.preview.focus() this.refs.preview.focus()
this.refs.preview.scrollTo(cursorPosition.line) this.refs.preview.scrollTo(cursorPosition.line)
eventEmitter.emit('topbar:lock')
}) })
} }
} }
@@ -109,6 +111,7 @@ class MarkdownEditor extends React.Component {
status: 'CODE' status: 'CODE'
}, () => { }, () => {
this.refs.code.focus() this.refs.code.focus()
eventEmitter.emit('topbar:lock')
}) })
} }
} }
@@ -145,6 +148,7 @@ class MarkdownEditor extends React.Component {
this.refs.code.focus() this.refs.code.focus()
}) })
} else { } else {
eventEmitter.emit('topbar:lock')
this.refs.code.focus() this.refs.code.focus()
} }
} }

View File

@@ -26,7 +26,7 @@ class MarkdownNoteDetail extends React.Component {
title: '', title: '',
content: '' content: ''
}, props.note), }, props.note),
isCODE: false, editorStatus: false,
locked: false locked: false
} }
this.dispatchTimer = null this.dispatchTimer = null
@@ -213,8 +213,8 @@ class MarkdownNoteDetail extends React.Component {
} }
handleLockButtonClick () { handleLockButtonClick () {
ee.emit('editor:lock')
this.focus() this.focus()
ee.emit('editor:lock')
this.setState({ locked: !this.state.locked }) this.setState({ locked: !this.state.locked })
} }
@@ -227,7 +227,11 @@ class MarkdownNoteDetail extends React.Component {
} }
handleShowLockButton () { handleShowLockButton () {
this.setState({isCODE: !this.state.isCODE}) this.setState({editorStatus: this.refs.content.state.status})
}
handleFocus (e) {
this.focus()
} }
render () { render () {
@@ -263,9 +267,10 @@ class MarkdownNoteDetail extends React.Component {
<div styleName='info-right'> <div styleName='info-right'>
{(() => { {(() => {
let faClassName=`fa ${this.toggleLockButton()}` let faClassName=`fa ${this.toggleLockButton()}`
if (this.state.isCODE) { if (this.state.editorStatus === 'CODE') {
return( return(
<button styleName='info-right-button' <button styleName='info-right-button'
onFocus={(e) => this.handleFocus(e)}
onClick={(e) => this.handleLockButtonClick(e)} onClick={(e) => this.handleLockButtonClick(e)}
> >
<i className={faClassName}/> <i className={faClassName}/>