1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

Improvement on the code

The improvement was suggested by github
This commit is contained in:
richardtks
2018-11-10 20:29:24 +08:00
parent ad7b155a99
commit aa56aad46e

View File

@@ -427,12 +427,14 @@ class NoteList extends React.Component {
selectedNoteKeys.push(uniqueKey) selectedNoteKeys.push(uniqueKey)
if (shiftKeyDown && hasSelectedNoteKey) { if (shiftKeyDown && hasSelectedNoteKey) {
const firstSelectedNoteIndex = const firstSelectedNoteIndex = selectedNoteKeys[0] > this.state.firstShiftSelectedNoteIndex
Math.max(this.getNoteIndexByKey(selectedNoteKeys[0]), ? selectedNoteKeys[0] : this.state.firstShiftSelectedNoteIndex
this.state.firstShiftSelectedNoteIndex)
const lastSelectedNoteIndex = this.getNoteIndexByKey(uniqueKey) const lastSelectedNoteIndex = this.getNoteIndexByKey(uniqueKey)
const startIndex = Math.min(firstSelectedNoteIndex, lastSelectedNoteIndex) const startIndex = firstSelectedNoteIndex < lastSelectedNoteIndex
const endIndex = Math.max(firstSelectedNoteIndex, lastSelectedNoteIndex) ? firstSelectedNoteIndex : lastSelectedNoteIndex
const endIndex = firstSelectedNoteIndex > lastSelectedNoteIndex
? firstSelectedNoteIndex : lastSelectedNoteIndex
selectedNoteKeys = [] selectedNoteKeys = []
for (let i = startIndex; i <= endIndex; i++) { for (let i = startIndex; i <= endIndex; i++) {
selectedNoteKeys.push(this.notes[i].key) selectedNoteKeys.push(this.notes[i].key)