mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Add a shortcut which jumps to top by Ctrl-G
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user