1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 10:16:26 +00:00

Fix to use by preventDefault

This commit is contained in:
asmsuechan
2017-02-11 23:00:24 +09:00
parent e9525fae22
commit bbeeeccb31
2 changed files with 15 additions and 17 deletions

View File

@@ -15,7 +15,7 @@ class MarkdownEditor extends React.Component {
status: 'PREVIEW', status: 'PREVIEW',
renderValue: props.value, renderValue: props.value,
keyPressed: {}, keyPressed: {},
locked: false isLocked: false
} }
this.lockEditorCode = () => this.handleLockEditor() this.lockEditorCode = () => this.handleLockEditor()
@@ -74,18 +74,17 @@ 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')
} }
eventEmitter.emit('topbar:showlockbutton')
}) })
} }
} }
handleBlur (e) { handleBlur (e) {
if (this.state.locked) return if (this.state.isLocked) return
this.setState({ keyPressed: [] }) this.setState({ keyPressed: [] })
let { config } = this.props let { config } = this.props
if (config.editor.switchPreview === 'BLUR') { if (config.editor.switchPreview === 'BLUR') {
@@ -95,8 +94,8 @@ class MarkdownEditor extends React.Component {
}, () => { }, () => {
this.refs.preview.focus() this.refs.preview.focus()
this.refs.preview.scrollTo(cursorPosition.line) this.refs.preview.scrollTo(cursorPosition.line)
eventEmitter.emit('topbar:lock')
}) })
eventEmitter.emit('topbar:showlockbutton')
} }
} }
@@ -111,8 +110,8 @@ class MarkdownEditor extends React.Component {
status: 'CODE' status: 'CODE'
}, () => { }, () => {
this.refs.code.focus() this.refs.code.focus()
eventEmitter.emit('topbar:lock')
}) })
eventEmitter.emit('topbar:showlockbutton')
} }
} }
@@ -144,13 +143,12 @@ class MarkdownEditor extends React.Component {
this.setState({ this.setState({
status: 'CODE' status: 'CODE'
}, () => { }, () => {
eventEmitter.emit('topbar:lock')
this.refs.code.focus() this.refs.code.focus()
}) })
} else { } else {
eventEmitter.emit('topbar:lock')
this.refs.code.focus() this.refs.code.focus()
} }
eventEmitter.emit('topbar:showlockbutton')
} }
reload () { reload () {
@@ -165,7 +163,7 @@ class MarkdownEditor extends React.Component {
}) })
this.setState({ keyPressed }) this.setState({ keyPressed })
let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] } let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] }
if (!this.state.locked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) { if (!this.state.isLocked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
document.activeElement.blur() document.activeElement.blur()
} }
} }
@@ -178,7 +176,7 @@ class MarkdownEditor extends React.Component {
} }
handleLockEditor () { handleLockEditor () {
this.setState({ locked: !this.state.locked }) this.setState({ isLocked: !this.state.isLocked })
} }
render () { render () {

View File

@@ -27,7 +27,7 @@ class MarkdownNoteDetail extends React.Component {
content: '' content: ''
}, props.note), }, props.note),
editorStatus: false, editorStatus: false,
locked: false isLocked: false
} }
this.dispatchTimer = null this.dispatchTimer = null
@@ -39,7 +39,7 @@ class MarkdownNoteDetail extends React.Component {
} }
componentDidMount () { componentDidMount () {
ee.on('topbar:lock', this.showLockButton) ee.on('topbar:showlockbutton', this.showLockButton)
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
@@ -212,14 +212,14 @@ class MarkdownNoteDetail extends React.Component {
} }
} }
handleLockButtonClick () { handleLockButtonMouseDown (e) {
this.focus() e.preventDefault()
ee.emit('editor:lock') ee.emit('editor:lock')
this.setState({ locked: !this.state.locked }) this.setState({ isLocked: !this.state.isLocked })
} }
toggleLockButton () { toggleLockButton () {
return this.state.locked ? 'fa-lock' : 'fa-unlock-alt' return this.state.isLocked ? 'fa-lock' : 'fa-unlock-alt'
} }
handleDeleteKeyDown (e) { handleDeleteKeyDown (e) {
@@ -271,7 +271,7 @@ class MarkdownNoteDetail extends React.Component {
return( return(
<button styleName='info-right-button' <button styleName='info-right-button'
onFocus={(e) => this.handleFocus(e)} onFocus={(e) => this.handleFocus(e)}
onClick={(e) => this.handleLockButtonClick(e)} onMouseDown={(e) => this.handleLockButtonMouseDown(e)}
> >
<i className={faClassName}/> <i className={faClassName}/>
</button> </button>