Skip to content

Commit 1dcc51e

Browse files
authored
Merge pull request #2499 from daiyam/store-editor-status
store editor view into config
2 parents 00ed0d7 + eb61ce2 commit 1dcc51e

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
@@ -76,9 +77,7 @@ class MarkdownEditor extends React.Component {
7677
handleContextMenu (e) {
7778
const { config } = this.props
7879
if (config.editor.switchPreview === 'RIGHTCLICK') {
79-
const newStatus = this.state.status === 'PREVIEW'
80-
? 'CODE'
81-
: 'PREVIEW'
80+
const newStatus = this.state.status === 'PREVIEW' ? 'CODE' : 'PREVIEW'
8281
this.setState({
8382
status: newStatus
8483
}, () => {
@@ -88,6 +87,10 @@ class MarkdownEditor extends React.Component {
8887
this.refs.preview.focus()
8988
}
9089
eventEmitter.emit('topbar:togglelockbutton', this.state.status)
90+
91+
const newConfig = Object.assign({}, config)
92+
newConfig.editor.delfaultStatus = newStatus
93+
ConfigManager.set(newConfig)
9194
})
9295
}
9396
}
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
@@ -44,9 +44,10 @@ export const DEFAULT_CONFIG = {
4444
enableRulers: false,
4545
rulers: [80, 120],
4646
displayLineNumbers: true,
47-
switchPreview: 'BLUR', // Available value: RIGHTCLICK, BLUR
47+
switchPreview: 'BLUR', // 'BLUR', 'DBL_CLICK', 'RIGHTCLICK'
48+
delfaultStatus: 'PREVIEW', // 'PREVIEW', 'CODE'
4849
scrollPastEnd: false,
49-
type: 'SPLIT',
50+
type: 'SPLIT', // 'SPLIT', 'EDITOR_PREVIEW'
5051
fetchUrlTitle: true,
5152
enableTableEditor: false,
5253
enableFrontMatterTitle: true,

0 commit comments

Comments
 (0)