1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Add a shortcut which jumps to top by Ctrl-G

This commit is contained in:
asmsuechan
2017-03-18 23:45:23 -07:00
parent b7ca4668e9
commit cec4b3132c
2 changed files with 32 additions and 0 deletions

View File

@@ -42,6 +42,10 @@ class NoteList extends React.Component {
this.alertIfSnippet()
}
this.jumpToTopHandler = () => {
this.jumpToTop()
}
this.state = {
}
}
@@ -52,6 +56,8 @@ class NoteList extends React.Component {
ee.on('list:prior', this.selectPriorNoteHandler)
ee.on('list:focus', this.focusHandler)
ee.on('list:isMarkdownNote', this.alertIfSnippetHandler)
ee.on('list:top', this.jumpToTopHandler)
ee.on('list:jumpToTop', this.jumpToTopHandler)
}
componentWillReceiveProps (nextProps) {
@@ -71,6 +77,8 @@ class NoteList extends React.Component {
ee.off('list:prior', this.selectPriorNoteHandler)
ee.off('list:focus', this.focusHandler)
ee.off('list:isMarkdownNote', this.alertIfSnippetHandler)
ee.off('list:top', this.jumpToTopHandler)
ee.off('list:jumpToTop', this.jumpToTopHandler)
}
componentDidUpdate (prevProps) {
@@ -324,6 +332,23 @@ class NoteList extends React.Component {
}
}
jumpToTop() {
if (this.notes == null || this.notes.length === 0) {
return
}
let { router } = this.context
let { location } = this.props
let targetIndex = 0
router.push({
pathname: location.pathname,
query: {
key: this.notes[targetIndex].storage + '-' + this.notes[targetIndex].key
}
})
}
render () {
let { location, notes, config } = this.props
let sortFunc = config.sortBy === 'CREATED_AT'