diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index dc6e0cd4..843d644a 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -191,8 +191,8 @@ CodeEditor.propTypes = { key: PropTypes.string }), className: PropTypes.string, - onChange: PropTypes.func, onBlur: PropTypes.func, + onChange: PropTypes.func, readOnly: PropTypes.bool } diff --git a/browser/main/HomePage/ArticleDetail/ArticleEditor.js b/browser/main/HomePage/ArticleDetail/ArticleEditor.js index 7673424e..378133d6 100644 --- a/browser/main/HomePage/ArticleDetail/ArticleEditor.js +++ b/browser/main/HomePage/ArticleDetail/ArticleEditor.js @@ -3,21 +3,42 @@ import ReactDOM from 'react-dom' import MarkdownPreview from 'browser/components/MarkdownPreview' import CodeEditor from 'browser/components/CodeEditor' import activityRecord from 'browser/lib/activityRecord' +import fetchConfig from 'browser/lib/fetchConfig' + +const electron = require('electron') +const ipc = electron.ipcRenderer export const PREVIEW_MODE = 'PREVIEW_MODE' export const EDIT_MODE = 'EDIT_MODE' +let config = fetchConfig() +ipc.on('config-apply', function (e, newConfig) { + config = newConfig +}) + export default class ArticleEditor extends React.Component { constructor (props) { super(props) + + this.configApplyHandler = (e, config) => this.handleConfigApply(e, config) this.isMouseDown = false this.state = { status: PREVIEW_MODE, cursorPosition: null, - firstVisibleRow: null + firstVisibleRow: null, + switchPreview: config['switch-preview'] } } + componentDidMount () { + console.log(this.state.switchPreview) + ipc.on('config-apply', this.configApplyHandler) + } + + componentWillUnmount () { + ipc.removeListener('config-apply', this.configApplyHandler) + } + componentWillReceiveProps (nextProps) { if (nextProps.article.key !== this.props.article.key) { this.setState({ @@ -26,6 +47,12 @@ export default class ArticleEditor extends React.Component { } } + handleConfigApply (e, newConfig) { + this.setState({ + switchPreview: newConfig['switch-preview'] + }) + } + resetCursorPosition () { this.setState({ cursorPosition: null, @@ -70,14 +97,15 @@ export default class ArticleEditor extends React.Component { } handlePreviewMouseDown (e) { - if (e.button === 2) return true - this.isDrag = false - this.isMouseDown = true - this.moveCount = 0 + if (this.state.switchPreview === 'blur' && e.button === 0) { + this.isDrag = false + this.isMouseDown = true + this.moveCount = 0 + } } handlePreviewMouseMove () { - if (this.isMouseDown) { + if (this.state.switchPreview === 'blur' && this.isMouseDown) { this.moveCount++ if (this.moveCount > 5) { this.isDrag = true @@ -86,17 +114,32 @@ export default class ArticleEditor extends React.Component { } handlePreviewMouseUp (e) { - if (e.button === 2) return true - this.isMouseDown = false - this.moveCount = 0 - if (!this.isDrag) { - this.switchEditMode() + 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) { + if (isFocusingToThis || this.state.switchPreview !== 'blur') { return } @@ -115,7 +158,7 @@ export default class ArticleEditor extends React.Component { let showPreview = article.mode === 'markdown' && this.state.status === PREVIEW_MODE if (showPreview) { return ( -
+
this.handleRightClickPreview(e)} className='ArticleEditor'> this.handlePreviewMouseUp(e)} @@ -123,13 +166,18 @@ export default class ArticleEditor extends React.Component { onMouseMove={e => this.handlePreviewMouseMove(e)} content={article.content} /> -
Click to Edit
+
) } return ( -
+
this.handleRightClickCodeEditor(e)} tabIndex='5' className='ArticleEditor'> this.handleBlurCodeEditor(e)} @@ -138,7 +186,13 @@ export default class ArticleEditor extends React.Component { /> {article.mode === 'markdown' ? ( -
Press ESC to watch Preview
+
) : null } diff --git a/browser/main/modal/Preference/AppSettingTab.js b/browser/main/modal/Preference/AppSettingTab.js index 8b73a6d3..8e284fd2 100644 --- a/browser/main/modal/Preference/AppSettingTab.js +++ b/browser/main/modal/Preference/AppSettingTab.js @@ -138,9 +138,9 @@ export default class AppSettingTab extends React.Component { this.handleConfigKeyDown(e)} type='text'/>
-
+
-
+
type this.handleConfigKeyDown(e)} type='text'/>
+
+ + +
{ - true// !OSX + global.process.platform === 'win32' ? (
diff --git a/browser/styles/main/modal/Preferences.styl b/browser/styles/main/modal/Preferences.styl index 9587ba2e..896e51bc 100644 --- a/browser/styles/main/modal/Preferences.styl +++ b/browser/styles/main/modal/Preferences.styl @@ -60,7 +60,7 @@ iptFocusBorderColor = #369DCD left 180px overflow-y auto &>.section - padding 10px + padding 10px 20px border-bottom 1px solid borderColor overflow-y auto &:nth-last-child(1) @@ -102,7 +102,6 @@ iptFocusBorderColor = #369DCD &:focus border-color iptFocusBorderColor &>.sectionSelect - margin-bottom 5px clearfix() height 33px @@ -111,7 +110,28 @@ iptFocusBorderColor = #369DCD padding-left 15px float left line-height 33px - .sectionSelect-input + select + float left + width 200px + height 25px + margin-top 4px + border-radius 5px + border 1px solid borderColor + padding 0 10px + font-size 14px + outline none + &:focus + border-color iptFocusBorderColor + &>.sectionMultiSelect + margin-bottom 5px + clearfix() + height 33px + label + width 150px + padding-left 15px + float left + line-height 33px + .sectionMultiSelect-input float left select width 80px diff --git a/lib/config.js b/lib/config.js index b2768452..e79f2bec 100644 --- a/lib/config.js +++ b/lib/config.js @@ -11,6 +11,7 @@ const defaultConfig = { 'editor-indent-size': '4', 'preview-font-size': '14', 'preview-font-family': 'Lato', + 'switch-preview': 'blur', 'disable-direct-write': false } const configFile = 'config.json'