From aa56aad46e8a5c573236dc6ed17fedb736d84ea5 Mon Sep 17 00:00:00 2001 From: richardtks Date: Sat, 10 Nov 2018 20:29:24 +0800 Subject: [PATCH] Improvement on the code The improvement was suggested by github --- browser/main/NoteList/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 2ad529e2..af89f878 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -427,12 +427,14 @@ class NoteList extends React.Component { selectedNoteKeys.push(uniqueKey) if (shiftKeyDown && hasSelectedNoteKey) { - const firstSelectedNoteIndex = - Math.max(this.getNoteIndexByKey(selectedNoteKeys[0]), - this.state.firstShiftSelectedNoteIndex) + const firstSelectedNoteIndex = selectedNoteKeys[0] > this.state.firstShiftSelectedNoteIndex + ? selectedNoteKeys[0] : this.state.firstShiftSelectedNoteIndex const lastSelectedNoteIndex = this.getNoteIndexByKey(uniqueKey) - const startIndex = Math.min(firstSelectedNoteIndex, lastSelectedNoteIndex) - const endIndex = Math.max(firstSelectedNoteIndex, lastSelectedNoteIndex) + const startIndex = firstSelectedNoteIndex < lastSelectedNoteIndex + ? firstSelectedNoteIndex : lastSelectedNoteIndex + const endIndex = firstSelectedNoteIndex > lastSelectedNoteIndex + ? firstSelectedNoteIndex : lastSelectedNoteIndex + selectedNoteKeys = [] for (let i = startIndex; i <= endIndex; i++) { selectedNoteKeys.push(this.notes[i].key)