From 116344737ac2b34c69584121e5a72d4791d944fb Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Sat, 16 Jan 2016 04:24:09 +0900 Subject: [PATCH] right click to quick preview(edit on focus) --- .../HomePage/ArticleDetail/ArticleEditor.js | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/browser/main/HomePage/ArticleDetail/ArticleEditor.js b/browser/main/HomePage/ArticleDetail/ArticleEditor.js index 378133d6..f53fc066 100644 --- a/browser/main/HomePage/ArticleDetail/ArticleEditor.js +++ b/browser/main/HomePage/ArticleDetail/ArticleEditor.js @@ -26,7 +26,8 @@ export default class ArticleEditor extends React.Component { status: PREVIEW_MODE, cursorPosition: 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 firstVisibleRow = this.refs.editor.getFirstVisibleRow() this.setState({ status: PREVIEW_MODE, cursorPosition, - firstVisibleRow + firstVisibleRow, + isTemporary: isTemporary }, function () { let previewEl = ReactDOM.findDOMNode(this.refs.preview) let anchors = previewEl.querySelectorAll('.lineAnchor') @@ -83,16 +85,18 @@ export default class ArticleEditor extends React.Component { }) } - switchEditMode () { + switchEditMode (isTemporary = false) { this.setState({ - status: EDIT_MODE + status: EDIT_MODE, + isTemporary: false }, function () { if (this.state.cursorPosition != null) { this.refs.editor.moveCursorTo(this.state.cursorPosition.row, this.state.cursorPosition.column) this.refs.editor.scrollToLine(this.state.firstVisibleRow) } 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) } + 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 () { let { article } = this.props let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE if (showPreview) { return ( -
this.handleRightClickPreview(e)} className='ArticleEditor'> +
this.handleRightClickPreview(e)} + onMouseUp={e => this.handleMouseUp(e)} + onMouseDown={e => this.handleMouseDowm(e)} + className='ArticleEditor' + > this.handlePreviewMouseUp(e)} @@ -177,7 +198,13 @@ export default class ArticleEditor extends React.Component { } return ( -
this.handleRightClickCodeEditor(e)} tabIndex='5' className='ArticleEditor'> +
this.handleRightClickCodeEditor(e)} + tabIndex='5' + onMouseUp={e => this.handleMouseUp(e)} + onMouseDown={e => this.handleMouseDowm(e)} + className='ArticleEditor' + > this.handleBlurCodeEditor(e)}