diff --git a/browser/main/HomePage/ArticleDetail/ArticleEditor.js b/browser/main/HomePage/ArticleDetail/ArticleEditor.js index f53fc066..b106104f 100644 --- a/browser/main/HomePage/ArticleDetail/ArticleEditor.js +++ b/browser/main/HomePage/ArticleDetail/ArticleEditor.js @@ -100,47 +100,6 @@ export default class ArticleEditor extends React.Component { }) } - handlePreviewMouseDown (e) { - if (this.state.switchPreview === 'blur' && e.button === 0) { - this.isDrag = false - this.isMouseDown = true - this.moveCount = 0 - } - } - - handlePreviewMouseMove () { - if (this.state.switchPreview === 'blur' && this.isMouseDown) { - this.moveCount++ - if (this.moveCount > 5) { - this.isDrag = true - } - } - } - - handlePreviewMouseUp (e) { - if (this.state.switchPreview === 'blur' && e.button === 0) { - this.isMouseDown = false - this.moveCount = 0 - if (!this.isDrag) { - this.switchEditMode() - } - } - } - - handleRightClickPreview (e) { - let { article } = this.props - if (this.state.switchPreview !== 'rightclick' || article.mode !== 'markdown') return true - - this.switchEditMode() - } - - handleRightClickCodeEditor (e) { - let { article } = this.props - if (this.state.switchPreview !== 'rightclick' || article.mode !== 'markdown') return true - - this.switchPreviewMode() - } - handleBlurCodeEditor (e) { let isFocusingToThis = e.relatedTarget === ReactDOM.findDOMNode(this) if (isFocusingToThis || this.state.switchPreview !== 'blur') { @@ -157,70 +116,97 @@ export default class ArticleEditor extends React.Component { this.props.onChange(value) } + handleRightClick (e) { + let { article } = this.props + if (this.state.switchPreview === 'rightclick' && article.mode === 'markdown') { + if (this.state.status === EDIT_MODE) this.switchPreviewMode() + else this.switchEditMode() + } + } + handleMouseUp (e) { - if (e.button === 2 && this.state.switchPreview !== 'rightclick') { - if (this.state.isTemporary) this.switchEditMode(true) + switch (this.state.switchPreview) { + case 'blur': + switch (e.button) { + case 0: + this.isMouseDown = false + this.moveCount = 0 + if (!this.isDrag) { + this.switchEditMode() + } + break + case 2: + if (this.state.isTemporary) this.switchEditMode(true) + } + break + case 'rightclick': + } + } + + handleMouseMove (e) { + if (this.state.switchPreview === 'blur' && this.isMouseDown) { + this.moveCount++ + if (this.moveCount > 5) { + this.isDrag = true + } } } handleMouseDowm (e) { - if (e.button === 2 && this.state.switchPreview !== 'rightclick' && this.state.status === EDIT_MODE && this.props.article.mode === 'markdown') { - this.switchPreviewMode(true) + switch (this.state.switchPreview) { + case 'blur': + switch (e.button) { + case 0: + this.isDrag = false + this.isMouseDown = true + this.moveCount = 0 + break + case 2: + if (this.state.status === EDIT_MODE && this.props.article.mode === 'markdown') { + this.switchPreviewMode(true) + } + } + break + case 'rightclick': } } render () { let { article } = this.props let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE - if (showPreview) { - return ( -