From cec4b3132c0ee76db0b2d9186be3e00a46946e24 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 18 Mar 2017 23:45:23 -0700 Subject: [PATCH 1/4] 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' }, From dea0c4287b13078fd85b214e26e71fdf4ff4824b Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 15 Mar 2017 14:06:43 -0700 Subject: [PATCH 2/4] Fix let to const --- browser/main/NoteList/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 88f3a3e9..7bb3d4e5 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -339,7 +339,7 @@ class NoteList extends React.Component { let { router } = this.context let { location } = this.props - let targetIndex = 0 + const targetIndex = 0 router.push({ pathname: location.pathname, From 31c04de7b6fa406075dd25f911951cf73fb0a8ff Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sun, 19 Mar 2017 00:17:51 -0700 Subject: [PATCH 3/4] Change the name list:top to list:jumpToTop --- lib/main-menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main-menu.js b/lib/main-menu.js index 2b9a2a99..2dfe92ea 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -187,7 +187,7 @@ var view = { label: 'Jump to Top', accelerator: 'Control + G', click () { - mainWindow.webContents.send('list:top') + mainWindow.webContents.send('list:jumpToTop') } }, { From 525ab900bd7d4ae91020428792555890e229edca Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 18 Mar 2017 23:44:43 -0700 Subject: [PATCH 4/4] Fix == to === --- browser/main/NoteList/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 7bb3d4e5..b3267d05 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -333,7 +333,7 @@ class NoteList extends React.Component { } jumpToTop() { - if (this.notes == null || this.notes.length === 0) { + if (this.notes === null || this.notes.length === 0) { return } let { router } = this.context