Skip to content

Commit da0222f

Browse files
committed
esc to show preview when rightclick to toggle set
1 parent fb8a2eb commit da0222f

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

browser/components/CodeEditor.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export default class CodeEditor extends React.Component {
8787
name: 'Focus title',
8888
bindKey: {win: 'Esc', mac: 'Esc'},
8989
exec: function (editor, e) {
90-
remote.getCurrentWebContents().send('list-focus')
90+
let currentWindow = remote.getCurrentWebContents()
91+
if (config['switch-preview'] === 'rightclick') {
92+
currentWindow.send('detail-preview')
93+
}
94+
currentWindow.send('list-focus')
9195
},
9296
readOnly: true
9397
})

browser/main/HomePage/ArticleDetail/ArticleEditor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default class ArticleEditor extends React.Component {
6565
}
6666

6767
switchPreviewMode (isTemporary = false) {
68+
if (this.props.article.mode !== 'markdown') return true
6869
let cursorPosition = this.refs.editor.getCursorPosition()
6970
let firstVisibleRow = this.refs.editor.getFirstVisibleRow()
7071
this.setState({

browser/main/HomePage/ArticleDetail/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export default class ArticleDetail extends React.Component {
102102
if (isModalOpen()) return true
103103
if (this.refs.editor) this.refs.editor.switchEditMode()
104104
}
105+
this.previewHandler = e => {
106+
if (isModalOpen()) return true
107+
if (this.refs.editor) this.refs.editor.switchPreviewMode()
108+
}
105109

106110
this.state = {
107111
article: Object.assign({content: ''}, props.activeArticle),
@@ -120,6 +124,7 @@ export default class ArticleDetail extends React.Component {
120124
ipc.on('detail-uncache', this.uncacheHandler)
121125
ipc.on('detail-title', this.titleHandler)
122126
ipc.on('detail-edit', this.editHandler)
127+
ipc.on('detail-preview', this.previewHandler)
123128
}
124129

125130
componentWillUnmount () {
@@ -130,6 +135,7 @@ export default class ArticleDetail extends React.Component {
130135
ipc.removeListener('detail-uncache', this.uncacheHandler)
131136
ipc.removeListener('detail-title', this.titleHandler)
132137
ipc.removeListener('detail-edit', this.editHandler)
138+
ipc.removeListener('detail-preview', this.previewHandler)
133139
}
134140

135141
componentDidUpdate (prevProps, prevState) {

0 commit comments

Comments
 (0)