1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

enhance Editor UX again

This commit is contained in:
Dick Choi
2016-01-09 23:17:33 +09:00
parent a505227d01
commit 3105958afb
3 changed files with 24 additions and 14 deletions

View File

@@ -95,10 +95,9 @@ export default class ModeSelect extends React.Component {
break break
// esc // esc
case 27: case 27:
e.preventDefault() case 9:
e.stopPropagation() e.stopPropagation()
this.handleBlur() this.setIdle()
break
} }
if (this.props.onKeyDown) this.props.onKeyDown(e) if (this.props.onKeyDown) this.props.onKeyDown(e)
} }

View File

@@ -94,13 +94,13 @@ export default class ArticleDetail extends React.Component {
} }
this.titleHandler = e => { this.titleHandler = e => {
if (isModalOpen()) return true if (isModalOpen()) return true
let titleEl = ReactDOM.findDOMNode(this.refs.title) if (this.refs.title) {
titleEl.focus() this.focusTitle()
titleEl.select() }
} }
this.editHandler = e => { this.editHandler = e => {
if (isModalOpen()) return true if (isModalOpen()) return true
this.refs.editor.switchEditMode() if (this.refs.editor) this.refs.editor.switchEditMode()
} }
this.state = { this.state = {
@@ -136,11 +136,10 @@ export default class ArticleDetail extends React.Component {
if (this.props.activeArticle == null || prevProps.activeArticle == null || this.props.activeArticle.key !== prevProps.activeArticle.key) { if (this.props.activeArticle == null || prevProps.activeArticle == null || this.props.activeArticle.key !== prevProps.activeArticle.key) {
if (this.refs.editor) this.refs.editor.resetCursorPosition() if (this.refs.editor) this.refs.editor.resetCursorPosition()
} }
}
editArticle () { if (prevProps.activeArticle == null && this.props.activeArticle) {
ReactDOM.findDOMNode(this.refs.title).focus()
ReactDOM.findDOMNode(this.refs.title).select() }
} }
renderEmpty () { renderEmpty () {
@@ -233,9 +232,14 @@ export default class ArticleDetail extends React.Component {
e.preventDefault() e.preventDefault()
this.switchEditMode() this.switchEditMode()
} }
if (e.keyCode === 9 && e.shiftKey) { if (e.keyCode === 9 && e.shiftKey) {
e.preventDefault() e.preventDefault()
ReactDOM.findDOMNode(this.refs.title).focus() this.focusTitle()
}
if (e.keyCode === 27) {
this.focusTitle()
} }
} }
@@ -243,6 +247,14 @@ export default class ArticleDetail extends React.Component {
this.refs.editor.switchEditMode() this.refs.editor.switchEditMode()
} }
focusTitle () {
if (this.refs.title) {
let titleEl = ReactDOM.findDOMNode(this.refs.title)
titleEl.focus()
titleEl.select()
}
}
render () { render () {
let { folders, status, tags, activeArticle, modified, user } = this.props let { folders, status, tags, activeArticle, modified, user } = this.props
if (activeArticle == null) return this.renderEmpty() if (activeArticle == null) return this.renderEmpty()

View File

@@ -125,7 +125,6 @@ export default class ArticleTopBar extends React.Component {
} }
focusInput () { focusInput () {
console.log('focinp')
this.searchInput.focus() this.searchInput.focus()
} }
@@ -167,7 +166,7 @@ export default class ArticleTopBar extends React.Component {
dispatch(saveArticle(newArticle.key, newArticle, true)) dispatch(saveArticle(newArticle.key, newArticle, true))
if (isFolderFilterApplied) dispatch(switchFolder(targetFolders[0].name)) if (isFolderFilterApplied) dispatch(switchFolder(targetFolders[0].name))
remote.getCurrentWebContents().send('detail-edit') remote.getCurrentWebContents().send('detail-title')
} }
handleTutorialButtonClick (e) { handleTutorialButtonClick (e) {