diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index b8e44939..9bb50a87 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -82,7 +82,7 @@ class MarkdownEditor extends React.Component { this.refs.code.blur() this.refs.preview.focus() } - eventEmitter.emit('topbar:showlockbutton') + eventEmitter.emit('topbar:togglelockbutton', this.state.status) }) } } @@ -99,7 +99,7 @@ class MarkdownEditor extends React.Component { this.refs.preview.focus() this.refs.preview.scrollTo(cursorPosition.line) }) - eventEmitter.emit('topbar:showlockbutton') + eventEmitter.emit('topbar:togglelockbutton', this.state.status) } } @@ -115,7 +115,7 @@ class MarkdownEditor extends React.Component { }, () => { this.refs.code.focus() }) - eventEmitter.emit('topbar:showlockbutton') + eventEmitter.emit('topbar:togglelockbutton', this.state.status) } } @@ -152,7 +152,7 @@ class MarkdownEditor extends React.Component { } else { this.refs.code.focus() } - eventEmitter.emit('topbar:showlockbutton') + eventEmitter.emit('topbar:togglelockbutton', this.state.status) } reload () { diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index 90f26286..3f4a7a4d 100644 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -26,12 +26,12 @@ class MarkdownNoteDetail extends React.Component { title: '', content: '' }, props.note), - editorStatus: false, + isLockButtonShown: false, isLocked: false } this.dispatchTimer = null - this.showLockButton = this.handleShowLockButton.bind(this) + this.toggleLockButton = this.handleToggleLockButton.bind(this) } focus () { @@ -39,7 +39,7 @@ class MarkdownNoteDetail extends React.Component { } componentDidMount () { - ee.on('topbar:showlockbutton', this.showLockButton) + ee.on('topbar:togglelockbutton', this.toggleLockButton) } componentWillReceiveProps (nextProps) { @@ -59,7 +59,7 @@ class MarkdownNoteDetail extends React.Component { } componentDidUnmount () { - ee.off('topbar:lock', this.showLockButton) + ee.off('topbar:togglelockbutton', this.toggleLockButton) } findTitle (value) { @@ -219,6 +219,7 @@ class MarkdownNoteDetail extends React.Component { e.preventDefault() ee.emit('editor:lock') this.setState({ isLocked: !this.state.isLocked }) + if (this.state.isLocked) this.focus() } getToggleLockButton () { @@ -229,8 +230,13 @@ class MarkdownNoteDetail extends React.Component { if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e) } - handleShowLockButton () { - this.setState({editorStatus: this.refs.content.state.status}) + handleToggleLockButton (event, noteStatus) { + // first argument event is not used + if (this.props.config.editor.switchPreview === 'BLUR' && noteStatus === 'CODE') { + this.setState({isLockButtonShown: true}) + } else { + this.setState({isLockButtonShown: false}) + } } handleFocus (e) { @@ -271,17 +277,20 @@ class MarkdownNoteDetail extends React.Component { {(() => { const faClassName=`fa ${this.getToggleLockButton()}` const lockButtonComponent = - return ( - this.state.editorStatus === 'CODE' ? lockButtonComponent : '' + this.state.isLockButtonShown ? lockButtonComponent : '' ) })()} -