From a504a45d9907a2647fde74c9209bef69509853a4 Mon Sep 17 00:00:00 2001 From: voidSatisfaction Date: Sun, 5 Nov 2017 18:45:09 +0900 Subject: [PATCH] fix up and down key rendering problems --- browser/main/NoteList/index.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 2e900790..42e1f085 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -135,6 +135,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props + let { selectedNoteIds } = this.state let targetIndex = this.getTargetIndex() @@ -142,7 +143,15 @@ class NoteList extends React.Component { return } targetIndex-- - if (targetIndex < 0) targetIndex = 0 + + selectedNoteIds = [] + const priorNote = Object.assign({}, this.notes[targetIndex]) + const priorNoteKey = `${priorNote.storage}-${priorNote.key}` + selectedNoteIds.push(priorNoteKey) + + this.setState({ + selectedNoteIds + }) router.push({ pathname: location.pathname, @@ -158,6 +167,7 @@ class NoteList extends React.Component { } let { router } = this.context let { location } = this.props + let { selectedNoteIds } = this.state let targetIndex = this.getTargetIndex() @@ -169,6 +179,15 @@ class NoteList extends React.Component { else if (targetIndex > this.notes.length - 1) targetIndex === this.notes.length - 1 } + selectedNoteIds = [] + const nextNote = Object.assign({}, this.notes[targetIndex]) + const nextNoteKey = `${nextNote.storage}-${nextNote.key}` + selectedNoteIds.push(nextNoteKey) + + this.setState({ + selectedNoteIds + }) + router.push({ pathname: location.pathname, query: { @@ -202,10 +221,6 @@ class NoteList extends React.Component { } handleNoteListKeyDown (e) { - if (e.shiftKey) { - this.setState({ shiftKeyDown: true }) - } - if (e.metaKey || e.ctrlKey) return true if (e.keyCode === 65 && !e.shiftKey) { @@ -232,6 +247,10 @@ class NoteList extends React.Component { e.preventDefault() this.selectNextNote() } + + if (e.shiftKey) { + this.setState({ shiftKeyDown: true }) + } } handleNoteListKeyUp (e) {