Skip to content

Commit 82987cd

Browse files
committed
Fix the variable name to more appropriate one
1 parent aa56aad commit 82987cd

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

browser/main/NoteList/index.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class NoteList extends React.Component {
8686
this.state = {
8787
ctrlKeyDown: false,
8888
shiftKeyDown: false,
89-
firstShiftSelectedNoteIndex: -1,
89+
prevShiftNoteIndex: -1,
9090
selectedNoteKeys: []
9191
}
9292

@@ -409,9 +409,8 @@ class NoteList extends React.Component {
409409
handleNoteClick (e, uniqueKey) {
410410
const { router } = this.context
411411
const { location } = this.props
412-
let { selectedNoteKeys } = this.state
412+
let { selectedNoteKeys, prevShiftNoteIndex } = this.state
413413
const { ctrlKeyDown, shiftKeyDown } = this.state
414-
let firstShiftSelectedNoteIndex = -1
415414
const hasSelectedNoteKey = selectedNoteKeys.length > 0
416415

417416
if (ctrlKeyDown && selectedNoteKeys.includes(uniqueKey)) {
@@ -424,28 +423,40 @@ class NoteList extends React.Component {
424423
if (!ctrlKeyDown && !shiftKeyDown) {
425424
selectedNoteKeys = []
426425
}
426+
427+
if (!shiftKeyDown) {
428+
prevShiftNoteIndex = -1
429+
}
430+
427431
selectedNoteKeys.push(uniqueKey)
428432

429433
if (shiftKeyDown && hasSelectedNoteKey) {
430-
const firstSelectedNoteIndex = selectedNoteKeys[0] > this.state.firstShiftSelectedNoteIndex
431-
? selectedNoteKeys[0] : this.state.firstShiftSelectedNoteIndex
432-
const lastSelectedNoteIndex = this.getNoteIndexByKey(uniqueKey)
433-
const startIndex = firstSelectedNoteIndex < lastSelectedNoteIndex
434-
? firstSelectedNoteIndex : lastSelectedNoteIndex
435-
const endIndex = firstSelectedNoteIndex > lastSelectedNoteIndex
436-
? firstSelectedNoteIndex : lastSelectedNoteIndex
434+
let firstShiftNoteIndex = this.getNoteIndexByKey(selectedNoteKeys[0])
435+
// Shift selection can either start from first note in the exisiting selectedNoteKeys
436+
// or previous first shift note index
437+
firstShiftNoteIndex = firstShiftNoteIndex > prevShiftNoteIndex
438+
? firstShiftNoteIndex : prevShiftNoteIndex
439+
440+
const lastShiftNoteIndex = this.getNoteIndexByKey(uniqueKey)
441+
442+
const startIndex = firstShiftNoteIndex < lastShiftNoteIndex
443+
? firstShiftNoteIndex : lastShiftNoteIndex
444+
const endIndex = firstShiftNoteIndex > lastShiftNoteIndex
445+
? firstShiftNoteIndex : lastShiftNoteIndex
437446

438447
selectedNoteKeys = []
439448
for (let i = startIndex; i <= endIndex; i++) {
440449
selectedNoteKeys.push(this.notes[i].key)
441450
}
442451

443-
firstShiftSelectedNoteIndex = firstSelectedNoteIndex
452+
if (prevShiftNoteIndex < 0) {
453+
prevShiftNoteIndex = firstShiftNoteIndex
454+
}
444455
}
445456

446457
this.setState({
447458
selectedNoteKeys,
448-
firstShiftSelectedNoteIndex
459+
prevShiftNoteIndex
449460
})
450461

451462
router.push({

0 commit comments

Comments
 (0)