diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index a3787ec8..c3ee4733 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -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() } diff --git a/browser/main/Detail/NoteDetail.js b/browser/main/Detail/NoteDetail.js index fe2ee491..3264203b 100644 --- a/browser/main/Detail/NoteDetail.js +++ b/browser/main/Detail/NoteDetail.js @@ -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) { diff --git a/browser/main/Main.js b/browser/main/Main.js index 90a18a47..69310426 100644 --- a/browser/main/Main.js +++ b/browser/main/Main.js @@ -22,6 +22,7 @@ class Main extends React.Component { listWidth: config.listWidth } } + componentDidMount () { let { dispatch } = this.props diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 10a6488c..ece93ebf 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -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 () { diff --git a/browser/main/TopBar/TopBar.styl b/browser/main/TopBar/TopBar.styl index 56ad9c72..d8fb11dc 100644 --- a/browser/main/TopBar/TopBar.styl +++ b/browser/main/TopBar/TopBar.styl @@ -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 diff --git a/browser/main/TopBar/index.js b/browser/main/TopBar/index.js index e36087ab..76d71988 100644 --- a/browser/main/TopBar/index.js +++ b/browser/main/TopBar/index.js @@ -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) diff --git a/browser/main/lib/Commander.js b/browser/main/lib/Commander.js new file mode 100644 index 00000000..959de5f0 --- /dev/null +++ b/browser/main/lib/Commander.js @@ -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 +}