Skip to content

Commit ced3460

Browse files
committed
store editor's status in config
1 parent 71ae420 commit ced3460

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

browser/components/MarkdownEditor.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import CodeEditor from 'browser/components/CodeEditor'
66
import MarkdownPreview from 'browser/components/MarkdownPreview'
77
import eventEmitter from 'browser/main/lib/eventEmitter'
88
import { findStorage } from 'browser/lib/findStorage'
9+
import ConfigManager from 'browser/main/lib/ConfigManager'
910

1011
class MarkdownEditor extends React.Component {
1112
constructor (props) {
@@ -18,7 +19,7 @@ class MarkdownEditor extends React.Component {
1819
this.supportMdSelectionBold = [16, 17, 186]
1920

2021
this.state = {
21-
status: 'PREVIEW',
22+
status: props.config.editor.switchPreview === 'RIGHTCLICK' ? props.config.editor.delfaultStatus : 'PREVIEW',
2223
renderValue: props.value,
2324
keyPressed: new Set(),
2425
isLocked: false
@@ -72,9 +73,7 @@ class MarkdownEditor extends React.Component {
7273
handleContextMenu (e) {
7374
const { config } = this.props
7475
if (config.editor.switchPreview === 'RIGHTCLICK') {
75-
const newStatus = this.state.status === 'PREVIEW'
76-
? 'CODE'
77-
: 'PREVIEW'
76+
const newStatus = this.state.status === 'PREVIEW' ? 'CODE' : 'PREVIEW'
7877
this.setState({
7978
status: newStatus
8079
}, () => {
@@ -84,6 +83,10 @@ class MarkdownEditor extends React.Component {
8483
this.refs.preview.focus()
8584
}
8685
eventEmitter.emit('topbar:togglelockbutton', this.state.status)
86+
87+
const newConfig = Object.assign({}, this.props.config)
88+
newConfig.editor.delfaultStatus = newStatus
89+
ConfigManager.set(newConfig)
8790
})
8891
}
8992
}
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import PropTypes from 'prop-types'
2-
import React from 'react'
3-
import CSSModules from 'browser/lib/CSSModules'
4-
import styles from './ToggleModeButton.styl'
5-
import i18n from 'browser/lib/i18n'
6-
7-
const ToggleModeButton = ({
8-
onClick, editorType
9-
}) => (
10-
<div styleName='control-toggleModeButton'>
11-
<div styleName={editorType === 'SPLIT' ? 'active' : 'non-active'} onClick={() => onClick('SPLIT')}>
12-
<img styleName='item-star' src={editorType === 'EDITOR_PREVIEW' ? '../resources/icon/icon-mode-markdown-off-active.svg' : ''} />
13-
</div>
14-
<div styleName={editorType === 'EDITOR_PREVIEW' ? 'active' : 'non-active'} onClick={() => onClick('EDITOR_PREVIEW')}>
15-
<img styleName='item-star' src={editorType === 'EDITOR_PREVIEW' ? '' : '../resources/icon/icon-mode-split-on-active.svg'} />
16-
</div>
17-
<span styleName='tooltip'>{i18n.__('Toggle Mode')}</span>
18-
</div>
19-
)
20-
21-
ToggleModeButton.propTypes = {
22-
onClick: PropTypes.func.isRequired,
23-
editorType: PropTypes.string.Required
24-
}
25-
26-
export default CSSModules(ToggleModeButton, styles)
1+
import PropTypes from 'prop-types'
2+
import React from 'react'
3+
import CSSModules from 'browser/lib/CSSModules'
4+
import styles from './ToggleModeButton.styl'
5+
import i18n from 'browser/lib/i18n'
6+
7+
const ToggleModeButton = ({
8+
onClick, editorType
9+
}) => (
10+
<div styleName='control-toggleModeButton'>
11+
<div styleName={editorType === 'SPLIT' ? 'active' : 'non-active'} onClick={() => onClick('SPLIT')}>
12+
<img styleName='item-star' src={editorType === 'EDITOR_PREVIEW' ? '../resources/icon/icon-mode-markdown-off-active.svg' : ''} />
13+
</div>
14+
<div styleName={editorType === 'EDITOR_PREVIEW' ? 'active' : 'non-active'} onClick={() => onClick('EDITOR_PREVIEW')}>
15+
<img styleName='item-star' src={editorType === 'EDITOR_PREVIEW' ? '' : '../resources/icon/icon-mode-split-on-active.svg'} />
16+
</div>
17+
<span styleName='tooltip'>{i18n.__('Toggle Mode')}</span>
18+
</div>
19+
)
20+
21+
ToggleModeButton.propTypes = {
22+
onClick: PropTypes.func.isRequired,
23+
editorType: PropTypes.string.Required
24+
}
25+
26+
export default CSSModules(ToggleModeButton, styles)

browser/main/lib/ConfigManager.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ export const DEFAULT_CONFIG = {
4343
enableRulers: false,
4444
rulers: [80, 120],
4545
displayLineNumbers: true,
46-
switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR
46+
switchPreview: 'BLUR', // 'BLUR', 'DBL_CLICK', 'RIGHTCLICK'
47+
delfaultStatus: 'PREVIEW', // 'PREVIEW', 'CODE'
4748
scrollPastEnd: false,
48-
type: 'SPLIT',
49+
type: 'SPLIT', // 'SPLIT', 'EDITOR_PREVIEW'
4950
fetchUrlTitle: true,
5051
enableTableEditor: false
5152
},

0 commit comments

Comments
 (0)