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

focus content editor after create new Note

This commit is contained in:
Dick Choi
2016-06-12 19:55:39 +09:00
parent eb1a0ba49f
commit ce915df2b2
7 changed files with 65 additions and 7 deletions

View File

@@ -42,6 +42,18 @@ class MarkdownEditor extends React.Component {
})
}
focus () {
if (this.state.status === 'PREVIEW') {
this.setState({
status: 'CODE'
}, () => {
this.refs.code.focus()
})
} else {
this.refs.code.focus()
}
}
reload () {
this.refs.code.reload()
}

View File

@@ -7,6 +7,7 @@ import StarButton from './StarButton'
import TagSelect from './TagSelect'
import FolderSelect from './FolderSelect'
import Repository from 'browser/lib/Repository'
import Commander from 'browser/main/lib/Commander'
class NoteDetail extends React.Component {
constructor (props) {
@@ -19,6 +20,21 @@ class NoteDetail extends React.Component {
this.dispatchTimer = null
}
componentDidMount () {
Commander.bind('note-detail', this)
}
componentWillUnmount () {
Commander.release(this)
}
fire (command) {
switch (command) {
case 'focus':
this.refs.content.focus()
}
}
componentWillReceiveProps (nextProps) {
if (nextProps.note.key !== this.props.note.key) {
if (this.state.isDispatchQueued) {

View File

@@ -22,6 +22,7 @@ class Main extends React.Component {
listWidth: config.listWidth
}
}
componentDidMount () {
let { dispatch } = this.props

View File

@@ -12,14 +12,11 @@ class NoteList extends React.Component {
}
componentDidMount () {
// this.refreshTimer = setInterval(() => this.forceUpdate(), 60 * 1000)
// ipc.on('list-focus', this.focusHandler)
// this.focus()
this.refreshTimer = setInterval(() => this.forceUpdate(), 60 * 1000)
}
componentWillUnmount () {
// clearInterval(this.refreshTimer)
// ipc.removeListener('list-focus', this.focusHandler)
clearInterval(this.refreshTimer)
}
componentDidUpdate () {

View File

@@ -63,7 +63,7 @@
background-color $ui-tooltip-backgroundColor
color $ui-tooltip-text-color
font-size 10px
margin-left -35px
margin-left -25px
margin-top 5px
padding 5px
z-index 1

View File

@@ -4,6 +4,7 @@ import styles from './TopBar.styl'
import activityRecord from 'browser/lib/activityRecord'
import Repository from 'browser/lib/Repository'
import _ from 'lodash'
import Commander from 'browser/main/lib/Commander'
const OSX = window.process.platform === 'darwin'
@@ -61,7 +62,6 @@ class TopBar extends React.Component {
Repository
.find(repositoryKey)
.then((repo) => {
console.log(repo)
return repo.addNote(newNote)
})
.then((note) => {
@@ -79,6 +79,7 @@ class TopBar extends React.Component {
key: `${note._repository.key}-${note.key}`
}
})
Commander.fire('note-detail:focus')
})
.catch((err) => {
console.error(err)

View File

@@ -0,0 +1,31 @@
let callees = []
function bind (name, el) {
callees.push({
name: name,
element: el
})
}
function release (el) {
callees = callees.filter((callee) => callee.element !== el)
}
function fire (command) {
console.info('COMMAND >>', command)
let splitted = command.split(':')
let target = splitted[0]
let targetCommand = splitted[1]
let targetCallees = callees
.filter((callee) => callee.name === target)
targetCallees.forEach((callee) => {
callee.element.fire(targetCommand)
})
}
export default {
bind,
release,
fire
}