mirror of
https://github.com/BoostIo/Boostnote
synced 2026-01-22 13:25:30 +00:00
Merge pull request #283 from asmsuechan/add-lock-to-CodeEditor
Enable lock in MarkdownEditor
This commit is contained in:
@@ -25,15 +25,23 @@ class MarkdownNoteDetail extends React.Component {
|
||||
note: Object.assign({
|
||||
title: '',
|
||||
content: ''
|
||||
}, props.note)
|
||||
}, props.note),
|
||||
editorStatus: false,
|
||||
isLocked: false
|
||||
}
|
||||
this.dispatchTimer = null
|
||||
|
||||
this.showLockButton = this.handleShowLockButton.bind(this)
|
||||
}
|
||||
|
||||
focus () {
|
||||
this.refs.content.focus()
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
ee.on('topbar:showlockbutton', this.showLockButton)
|
||||
}
|
||||
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
|
||||
if (this.saveQueue != null) this.saveNow()
|
||||
@@ -50,6 +58,10 @@ class MarkdownNoteDetail extends React.Component {
|
||||
if (this.saveQueue != null) this.saveNow()
|
||||
}
|
||||
|
||||
componentDidUnmount () {
|
||||
ee.off('topbar:lock', this.showLockButton)
|
||||
}
|
||||
|
||||
findTitle (value) {
|
||||
let splitted = value.split('\n')
|
||||
let title = null
|
||||
@@ -200,10 +212,28 @@ class MarkdownNoteDetail extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
handleLockButtonMouseDown (e) {
|
||||
e.preventDefault()
|
||||
ee.emit('editor:lock')
|
||||
this.setState({ isLocked: !this.state.isLocked })
|
||||
}
|
||||
|
||||
getToggleLockButton () {
|
||||
return this.state.isLocked ? 'fa-lock' : 'fa-unlock-alt'
|
||||
}
|
||||
|
||||
handleDeleteKeyDown (e) {
|
||||
if (e.keyCode === 27) this.handleDeleteCancelButtonClick(e)
|
||||
}
|
||||
|
||||
handleShowLockButton () {
|
||||
this.setState({editorStatus: this.refs.content.state.status})
|
||||
}
|
||||
|
||||
handleFocus (e) {
|
||||
this.focus()
|
||||
}
|
||||
|
||||
render () {
|
||||
let { data, config } = this.props
|
||||
let { note } = this.state
|
||||
@@ -235,6 +265,19 @@ class MarkdownNoteDetail extends React.Component {
|
||||
/>
|
||||
</div>
|
||||
<div styleName='info-right'>
|
||||
{(() => {
|
||||
const faClassName=`fa ${this.getToggleLockButton()}`
|
||||
const lockButtonComponent =
|
||||
<button styleName='info-right-button'
|
||||
onFocus={(e) => this.handleFocus(e)}
|
||||
onMouseDown={(e) => this.handleLockButtonMouseDown(e)}
|
||||
>
|
||||
<i className={faClassName}/>
|
||||
</button>
|
||||
return (
|
||||
this.state.editorStatus === 'CODE' ? lockButtonComponent : ''
|
||||
)
|
||||
})()}
|
||||
<button styleName='info-right-button'
|
||||
onClick={(e) => this.handleContextButtonClick(e)}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user