@@ -84,7 +84,9 @@ class NoteList extends React.Component {
84
84
85
85
// TODO: not Selected noteKeys but SelectedNote(for reusing)
86
86
this . state = {
87
+ ctrlKeyDown : false ,
87
88
shiftKeyDown : false ,
89
+ firstShiftSelectedNoteIndex : - 1 ,
88
90
selectedNoteKeys : [ ]
89
91
}
90
92
@@ -267,7 +269,7 @@ class NoteList extends React.Component {
267
269
}
268
270
269
271
handleNoteListKeyDown ( e ) {
270
- if ( e . metaKey || e . ctrlKey ) return true
272
+ if ( e . metaKey ) return true
271
273
272
274
// A key
273
275
if ( e . keyCode === 65 && ! e . shiftKey ) {
@@ -307,13 +309,19 @@ class NoteList extends React.Component {
307
309
308
310
if ( e . shiftKey ) {
309
311
this . setState ( { shiftKeyDown : true } )
312
+ } else if ( e . ctrlKey ) {
313
+ this . setState ( { ctrlKeyDown : true } )
310
314
}
311
315
}
312
316
313
317
handleNoteListKeyUp ( e ) {
314
318
if ( ! e . shiftKey ) {
315
319
this . setState ( { shiftKeyDown : false } )
316
320
}
321
+
322
+ if ( ! e . ctrlKey ) {
323
+ this . setState ( { ctrlKeyDown : false } )
324
+ }
317
325
}
318
326
319
327
getNotes ( ) {
@@ -390,25 +398,51 @@ class NoteList extends React.Component {
390
398
return pinnedNotes . concat ( unpinnedNotes )
391
399
}
392
400
401
+ getNoteIndexByKey ( noteKey ) {
402
+ return this . notes . findIndex ( ( note ) => {
403
+ if ( ! note ) return - 1
404
+
405
+ return note . key === noteKey
406
+ } )
407
+ }
408
+
393
409
handleNoteClick ( e , uniqueKey ) {
394
410
const { router } = this . context
395
411
const { location } = this . props
396
412
let { selectedNoteKeys } = this . state
397
- const { shiftKeyDown } = this . state
413
+ const { ctrlKeyDown, shiftKeyDown } = this . state
414
+ let firstShiftSelectedNoteIndex = - 1
398
415
399
- if ( shiftKeyDown && selectedNoteKeys . includes ( uniqueKey ) ) {
416
+ if ( ctrlKeyDown && selectedNoteKeys . includes ( uniqueKey ) ) {
400
417
const newSelectedNoteKeys = selectedNoteKeys . filter ( ( noteKey ) => noteKey !== uniqueKey )
401
418
this . setState ( {
402
419
selectedNoteKeys : newSelectedNoteKeys
403
420
} )
404
421
return
405
422
}
406
- if ( ! shiftKeyDown ) {
423
+ if ( ! ctrlKeyDown && ! shiftKeyDown ) {
407
424
selectedNoteKeys = [ ]
408
425
}
409
426
selectedNoteKeys . push ( uniqueKey )
427
+
428
+ if ( shiftKeyDown && selectedNoteKeys . length > 0 ) {
429
+ const firstSelectedNoteIndex =
430
+ Math . max ( this . getNoteIndexByKey ( selectedNoteKeys [ 0 ] ) ,
431
+ this . state . firstShiftSelectedNoteIndex )
432
+ const lastSelectedNoteIndex = this . getNoteIndexByKey ( uniqueKey )
433
+ const startIndex = Math . min ( firstSelectedNoteIndex , lastSelectedNoteIndex )
434
+ const endIndex = Math . max ( firstSelectedNoteIndex , lastSelectedNoteIndex )
435
+ selectedNoteKeys = [ ]
436
+ for ( let i = startIndex ; i <= endIndex ; i ++ ) {
437
+ selectedNoteKeys . push ( this . notes [ i ] . key )
438
+ }
439
+
440
+ firstShiftSelectedNoteIndex = firstSelectedNoteIndex
441
+ }
442
+
410
443
this . setState ( {
411
- selectedNoteKeys
444
+ selectedNoteKeys,
445
+ firstShiftSelectedNoteIndex
412
446
} )
413
447
414
448
router . push ( {
0 commit comments