mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
right click to quick preview(edit on focus)
This commit is contained in:
@@ -26,7 +26,8 @@ export default class ArticleEditor extends React.Component {
|
|||||||
status: PREVIEW_MODE,
|
status: PREVIEW_MODE,
|
||||||
cursorPosition: null,
|
cursorPosition: null,
|
||||||
firstVisibleRow: null,
|
firstVisibleRow: null,
|
||||||
switchPreview: config['switch-preview']
|
switchPreview: config['switch-preview'],
|
||||||
|
isTemporary: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,13 +64,14 @@ export default class ArticleEditor extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
switchPreviewMode () {
|
switchPreviewMode (isTemporary = false) {
|
||||||
let cursorPosition = this.refs.editor.getCursorPosition()
|
let cursorPosition = this.refs.editor.getCursorPosition()
|
||||||
let firstVisibleRow = this.refs.editor.getFirstVisibleRow()
|
let firstVisibleRow = this.refs.editor.getFirstVisibleRow()
|
||||||
this.setState({
|
this.setState({
|
||||||
status: PREVIEW_MODE,
|
status: PREVIEW_MODE,
|
||||||
cursorPosition,
|
cursorPosition,
|
||||||
firstVisibleRow
|
firstVisibleRow,
|
||||||
|
isTemporary: isTemporary
|
||||||
}, function () {
|
}, function () {
|
||||||
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
|
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
|
||||||
let anchors = previewEl.querySelectorAll('.lineAnchor')
|
let anchors = previewEl.querySelectorAll('.lineAnchor')
|
||||||
@@ -83,16 +85,18 @@ export default class ArticleEditor extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
switchEditMode () {
|
switchEditMode (isTemporary = false) {
|
||||||
this.setState({
|
this.setState({
|
||||||
status: EDIT_MODE
|
status: EDIT_MODE,
|
||||||
|
isTemporary: false
|
||||||
}, function () {
|
}, function () {
|
||||||
if (this.state.cursorPosition != null) {
|
if (this.state.cursorPosition != null) {
|
||||||
this.refs.editor.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
|
this.refs.editor.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
|
||||||
this.refs.editor.scrollToLine(this.state.firstVisibleRow)
|
this.refs.editor.scrollToLine(this.state.firstVisibleRow)
|
||||||
}
|
}
|
||||||
this.refs.editor.editor.focus()
|
this.refs.editor.editor.focus()
|
||||||
activityRecord.emit('ARTICLE_UPDATE', this.props.article)
|
|
||||||
|
if (!isTemporary) activityRecord.emit('ARTICLE_UPDATE', this.props.article)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +157,29 @@ export default class ArticleEditor extends React.Component {
|
|||||||
this.props.onChange(value)
|
this.props.onChange(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleMouseUp (e) {
|
||||||
|
if (e.button === 2 && this.state.switchPreview !== 'rightclick') {
|
||||||
|
if (this.state.isTemporary) this.switchEditMode(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleMouseDowm (e) {
|
||||||
|
if (e.button === 2 && this.state.switchPreview !== 'rightclick' && this.state.status === EDIT_MODE && this.props.article.mode === 'markdown') {
|
||||||
|
this.switchPreviewMode(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { article } = this.props
|
let { article } = this.props
|
||||||
let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE
|
let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE
|
||||||
if (showPreview) {
|
if (showPreview) {
|
||||||
return (
|
return (
|
||||||
<div onContextMenu={e => this.handleRightClickPreview(e)} className='ArticleEditor'>
|
<div
|
||||||
|
onContextMenu={e => this.handleRightClickPreview(e)}
|
||||||
|
onMouseUp={e => this.handleMouseUp(e)}
|
||||||
|
onMouseDown={e => this.handleMouseDowm(e)}
|
||||||
|
className='ArticleEditor'
|
||||||
|
>
|
||||||
<MarkdownPreview
|
<MarkdownPreview
|
||||||
ref='preview'
|
ref='preview'
|
||||||
onMouseUp={e => this.handlePreviewMouseUp(e)}
|
onMouseUp={e => this.handlePreviewMouseUp(e)}
|
||||||
@@ -177,7 +198,13 @@ export default class ArticleEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onContextMenu={e => this.handleRightClickCodeEditor(e)} tabIndex='5' className='ArticleEditor'>
|
<div
|
||||||
|
onContextMenu={e => this.handleRightClickCodeEditor(e)}
|
||||||
|
tabIndex='5'
|
||||||
|
onMouseUp={e => this.handleMouseUp(e)}
|
||||||
|
onMouseDown={e => this.handleMouseDowm(e)}
|
||||||
|
className='ArticleEditor'
|
||||||
|
>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
ref='editor'
|
ref='editor'
|
||||||
onBlur={e => this.handleBlurCodeEditor(e)}
|
onBlur={e => this.handleBlurCodeEditor(e)}
|
||||||
|
|||||||
Reference in New Issue
Block a user