Skip to content

Commit 1163447

Browse files
committed
right click to quick preview(edit on focus)
1 parent 93c03f4 commit 1163447

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

browser/main/HomePage/ArticleDetail/ArticleEditor.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default class ArticleEditor extends React.Component {
2626
status: PREVIEW_MODE,
2727
cursorPosition: null,
2828
firstVisibleRow: null,
29-
switchPreview: config['switch-preview']
29+
switchPreview: config['switch-preview'],
30+
isTemporary: false
3031
}
3132
}
3233

@@ -63,13 +64,14 @@ export default class ArticleEditor extends React.Component {
6364
})
6465
}
6566

66-
switchPreviewMode () {
67+
switchPreviewMode (isTemporary = false) {
6768
let cursorPosition = this.refs.editor.getCursorPosition()
6869
let firstVisibleRow = this.refs.editor.getFirstVisibleRow()
6970
this.setState({
7071
status: PREVIEW_MODE,
7172
cursorPosition,
72-
firstVisibleRow
73+
firstVisibleRow,
74+
isTemporary: isTemporary
7375
}, function () {
7476
let previewEl = ReactDOM.findDOMNode(this.refs.preview)
7577
let anchors = previewEl.querySelectorAll('.lineAnchor')
@@ -83,16 +85,18 @@ export default class ArticleEditor extends React.Component {
8385
})
8486
}
8587

86-
switchEditMode () {
88+
switchEditMode (isTemporary = false) {
8789
this.setState({
88-
status: EDIT_MODE
90+
status: EDIT_MODE,
91+
isTemporary: false
8992
}, function () {
9093
if (this.state.cursorPosition != null) {
9194
this.refs.editor.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column)
9295
this.refs.editor.scrollToLine(this.state.firstVisibleRow)
9396
}
9497
this.refs.editor.editor.focus()
95-
activityRecord.emit('ARTICLE_UPDATE', this.props.article)
98+
99+
if (!isTemporary) activityRecord.emit('ARTICLE_UPDATE', this.props.article)
96100
})
97101
}
98102

@@ -153,12 +157,29 @@ export default class ArticleEditor extends React.Component {
153157
this.props.onChange(value)
154158
}
155159

160+
handleMouseUp (e) {
161+
if (e.button === 2 && this.state.switchPreview !== 'rightclick') {
162+
if (this.state.isTemporary) this.switchEditMode(true)
163+
}
164+
}
165+
166+
handleMouseDowm (e) {
167+
if (e.button === 2 && this.state.switchPreview !== 'rightclick' && this.state.status === EDIT_MODE && this.props.article.mode === 'markdown') {
168+
this.switchPreviewMode(true)
169+
}
170+
}
171+
156172
render () {
157173
let { article } = this.props
158174
let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE
159175
if (showPreview) {
160176
return (
161-
<div onContextMenu={e => this.handleRightClickPreview(e)} className='ArticleEditor'>
177+
<div
178+
onContextMenu={e => this.handleRightClickPreview(e)}
179+
onMouseUp={e => this.handleMouseUp(e)}
180+
onMouseDown={e => this.handleMouseDowm(e)}
181+
className='ArticleEditor'
182+
>
162183
<MarkdownPreview
163184
ref='preview'
164185
onMouseUp={e => this.handlePreviewMouseUp(e)}
@@ -177,7 +198,13 @@ export default class ArticleEditor extends React.Component {
177198
}
178199

179200
return (
180-
<div onContextMenu={e => this.handleRightClickCodeEditor(e)} tabIndex='5' className='ArticleEditor'>
201+
<div
202+
onContextMenu={e => this.handleRightClickCodeEditor(e)}
203+
tabIndex='5'
204+
onMouseUp={e => this.handleMouseUp(e)}
205+
onMouseDown={e => this.handleMouseDowm(e)}
206+
className='ArticleEditor'
207+
>
181208
<CodeEditor
182209
ref='editor'
183210
onBlur={e => this.handleBlurCodeEditor(e)}

0 commit comments

Comments
 (0)