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

Add lock icon to NoteDetail

This commit is contained in:
asmsuechan
2017-02-11 15:48:38 +09:00
parent dbf1d6403b
commit 74ee6ae6ce
2 changed files with 42 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ import CSSModules from 'browser/lib/CSSModules'
import styles from './MarkdownEditor.styl'
import CodeEditor from 'browser/components/CodeEditor'
import MarkdownPreview from 'browser/components/MarkdownPreview'
import eventEmitter from 'browser/main/lib/eventEmitter'
class MarkdownEditor extends React.Component {
constructor (props) {
@@ -13,12 +14,18 @@ class MarkdownEditor extends React.Component {
this.state = {
status: 'PREVIEW',
renderValue: props.value,
keyPressed: {}
keyPressed: {},
locked: false
}
this.lockEditorCode = () => this.handleLockEditor()
this.getEditorStatus = () => this.handleGetEditorStatus()
}
componentDidMount () {
this.value = this.refs.code.value
eventEmitter.on('editor:lock', this.lockEditorCode)
eventEmitter.on('editor:status', this.getEditorStatus)
}
componentDidUpdate () {
@@ -33,6 +40,8 @@ class MarkdownEditor extends React.Component {
componentWillUnmount () {
this.cancelQueue()
eventEmitter.off('editor:lock', this.lockEditorCode)
eventEmitter.off('editor:status', this.getEditorStatus)
}
queueRendering (value) {
@@ -77,6 +86,7 @@ class MarkdownEditor extends React.Component {
}
handleBlur (e) {
if (this.state.locked) return
this.setState({ keyPressed: [] })
let { config } = this.props
if (config.editor.switchPreview === 'BLUR') {
@@ -152,7 +162,7 @@ class MarkdownEditor extends React.Component {
})
this.setState({ keyPressed })
let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] }
if (this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
if (!this.state.locked && this.state.status === 'CODE' && this.escapeFromEditor.every(isNoteHandlerKey)) {
document.activeElement.blur()
}
}
@@ -164,6 +174,10 @@ class MarkdownEditor extends React.Component {
this.setState({ keyPressed })
}
handleLockEditor () {
this.setState({ locked: !this.state.locked })
}
render () {
let { className, value, config } = this.props