Skip to content

Commit 3105958

Browse files
committed
enhance Editor UX again
1 parent a505227 commit 3105958

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

browser/components/ModeSelect.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ export default class ModeSelect extends React.Component {
9595
break
9696
// esc
9797
case 27:
98-
e.preventDefault()
98+
case 9:
9999
e.stopPropagation()
100-
this.handleBlur()
101-
break
100+
this.setIdle()
102101
}
103102
if (this.props.onKeyDown) this.props.onKeyDown(e)
104103
}

browser/main/HomePage/ArticleDetail/index.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ export default class ArticleDetail extends React.Component {
9494
}
9595
this.titleHandler = e => {
9696
if (isModalOpen()) return true
97-
let titleEl = ReactDOM.findDOMNode(this.refs.title)
98-
titleEl.focus()
99-
titleEl.select()
97+
if (this.refs.title) {
98+
this.focusTitle()
99+
}
100100
}
101101
this.editHandler = e => {
102102
if (isModalOpen()) return true
103-
this.refs.editor.switchEditMode()
103+
if (this.refs.editor) this.refs.editor.switchEditMode()
104104
}
105105

106106
this.state = {
@@ -136,11 +136,10 @@ export default class ArticleDetail extends React.Component {
136136
if (this.props.activeArticle == null || prevProps.activeArticle == null || this.props.activeArticle.key !== prevProps.activeArticle.key) {
137137
if (this.refs.editor) this.refs.editor.resetCursorPosition()
138138
}
139-
}
140139

141-
editArticle () {
142-
ReactDOM.findDOMNode(this.refs.title).focus()
143-
ReactDOM.findDOMNode(this.refs.title).select()
140+
if (prevProps.activeArticle == null && this.props.activeArticle) {
141+
142+
}
144143
}
145144

146145
renderEmpty () {
@@ -233,16 +232,29 @@ export default class ArticleDetail extends React.Component {
233232
e.preventDefault()
234233
this.switchEditMode()
235234
}
235+
236236
if (e.keyCode === 9 && e.shiftKey) {
237237
e.preventDefault()
238-
ReactDOM.findDOMNode(this.refs.title).focus()
238+
this.focusTitle()
239+
}
240+
241+
if (e.keyCode === 27) {
242+
this.focusTitle()
239243
}
240244
}
241245

242246
switchEditMode () {
243247
this.refs.editor.switchEditMode()
244248
}
245249

250+
focusTitle () {
251+
if (this.refs.title) {
252+
let titleEl = ReactDOM.findDOMNode(this.refs.title)
253+
titleEl.focus()
254+
titleEl.select()
255+
}
256+
}
257+
246258
render () {
247259
let { folders, status, tags, activeArticle, modified, user } = this.props
248260
if (activeArticle == null) return this.renderEmpty()

browser/main/HomePage/ArticleTopBar.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export default class ArticleTopBar extends React.Component {
125125
}
126126

127127
focusInput () {
128-
console.log('focinp')
129128
this.searchInput.focus()
130129
}
131130

@@ -167,7 +166,7 @@ export default class ArticleTopBar extends React.Component {
167166

168167
dispatch(saveArticle(newArticle.key, newArticle, true))
169168
if (isFolderFilterApplied) dispatch(switchFolder(targetFolders[0].name))
170-
remote.getCurrentWebContents().send('detail-edit')
169+
remote.getCurrentWebContents().send('detail-title')
171170
}
172171

173172
handleTutorialButtonClick (e) {

0 commit comments

Comments
 (0)