From cec4b3132c0ee76db0b2d9186be3e00a46946e24 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 18 Mar 2017 23:45:23 -0700 Subject: [PATCH] Add a shortcut which jumps to top by Ctrl-G --- browser/main/NoteList/index.js | 25 +++++++++++++++++++++++++ lib/main-menu.js | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 579dbe0b..88f3a3e9 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -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' diff --git a/lib/main-menu.js b/lib/main-menu.js index b3a7acc7..2b9a2a99 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -183,6 +183,13 @@ var view = { mainWindow.webContents.send('list:prior') } }, + { + label: 'Jump to Top', + accelerator: 'Control + G', + click () { + mainWindow.webContents.send('list:top') + } + }, { type: 'separator' },