@@ -86,7 +86,7 @@ class NoteList extends React.Component {
86
86
this . state = {
87
87
ctrlKeyDown : false ,
88
88
shiftKeyDown : false ,
89
- firstShiftSelectedNoteIndex : - 1 ,
89
+ prevShiftNoteIndex : - 1 ,
90
90
selectedNoteKeys : [ ]
91
91
}
92
92
@@ -409,9 +409,8 @@ class NoteList extends React.Component {
409
409
handleNoteClick ( e , uniqueKey ) {
410
410
const { router } = this . context
411
411
const { location } = this . props
412
- let { selectedNoteKeys } = this . state
412
+ let { selectedNoteKeys, prevShiftNoteIndex } = this . state
413
413
const { ctrlKeyDown, shiftKeyDown } = this . state
414
- let firstShiftSelectedNoteIndex = - 1
415
414
const hasSelectedNoteKey = selectedNoteKeys . length > 0
416
415
417
416
if ( ctrlKeyDown && selectedNoteKeys . includes ( uniqueKey ) ) {
@@ -424,28 +423,40 @@ class NoteList extends React.Component {
424
423
if ( ! ctrlKeyDown && ! shiftKeyDown ) {
425
424
selectedNoteKeys = [ ]
426
425
}
426
+
427
+ if ( ! shiftKeyDown ) {
428
+ prevShiftNoteIndex = - 1
429
+ }
430
+
427
431
selectedNoteKeys . push ( uniqueKey )
428
432
429
433
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
437
446
438
447
selectedNoteKeys = [ ]
439
448
for ( let i = startIndex ; i <= endIndex ; i ++ ) {
440
449
selectedNoteKeys . push ( this . notes [ i ] . key )
441
450
}
442
451
443
- firstShiftSelectedNoteIndex = firstSelectedNoteIndex
452
+ if ( prevShiftNoteIndex < 0 ) {
453
+ prevShiftNoteIndex = firstShiftNoteIndex
454
+ }
444
455
}
445
456
446
457
this . setState ( {
447
458
selectedNoteKeys,
448
- firstShiftSelectedNoteIndex
459
+ prevShiftNoteIndex
449
460
} )
450
461
451
462
router . push ( {
0 commit comments