@@ -231,16 +231,16 @@ export function reducer(state: TreeState, action: Action): TreeState {
231
231
const currentlySelected = state . nodes [ action . payload . id ] ?. selected ?? false ;
232
232
if ( currentlySelected ) {
233
233
return reducer ( state , { type : "DESELECT_NODE" , payload : { id : action . payload . id } } ) ;
234
- } else {
235
- return reducer ( state , {
236
- type : "SELECT_NODE" ,
237
- payload : {
238
- id : action . payload . id ,
239
- scrollToNode : action . payload . scrollToNode ,
240
- scrollToNodeFn : action . payload . scrollToNodeFn ,
241
- } ,
242
- } ) ;
243
234
}
235
+
236
+ return reducer ( state , {
237
+ type : "SELECT_NODE" ,
238
+ payload : {
239
+ id : action . payload . id ,
240
+ scrollToNode : action . payload . scrollToNode ,
241
+ scrollToNodeFn : action . payload . scrollToNodeFn ,
242
+ } ,
243
+ } ) ;
244
244
}
245
245
case "EXPAND_NODE" : {
246
246
const newNodes = {
@@ -277,16 +277,16 @@ export function reducer(state: TreeState, action: Action): TreeState {
277
277
type : "COLLAPSE_NODE" ,
278
278
payload : { id : action . payload . id } ,
279
279
} ) ;
280
- } else {
281
- return reducer ( state , {
282
- type : "EXPAND_NODE" ,
283
- payload : {
284
- id : action . payload . id ,
285
- scrollToNode : action . payload . scrollToNode ,
286
- scrollToNodeFn : action . payload . scrollToNodeFn ,
287
- } ,
288
- } ) ;
289
280
}
281
+
282
+ return reducer ( state , {
283
+ type : "EXPAND_NODE" ,
284
+ payload : {
285
+ id : action . payload . id ,
286
+ scrollToNode : action . payload . scrollToNode ,
287
+ scrollToNodeFn : action . payload . scrollToNodeFn ,
288
+ } ,
289
+ } ) ;
290
290
}
291
291
case "EXPAND_ALL_BELOW_DEPTH" : {
292
292
const nodesToExpand = state . tree . filter (
@@ -396,17 +396,17 @@ export function reducer(state: TreeState, action: Action): TreeState {
396
396
level : action . payload . level ,
397
397
} ,
398
398
} ) ;
399
- } else {
400
- return reducer ( state , {
401
- type : "EXPAND_LEVEL" ,
402
- payload : {
403
- level : action . payload . level ,
404
- } ,
405
- } ) ;
406
399
}
400
+
401
+ return reducer ( state , {
402
+ type : "EXPAND_LEVEL" ,
403
+ payload : {
404
+ level : action . payload . level ,
405
+ } ,
406
+ } ) ;
407
407
}
408
408
case "SELECT_FIRST_VISIBLE_NODE" : {
409
- const node = firstVisibleNode ( state . tree , state . nodes ) ;
409
+ const node = firstVisibleNode ( state . tree , state . filteredNodes ) ;
410
410
if ( node ) {
411
411
return reducer ( state , {
412
412
type : "SELECT_NODE" ,
@@ -417,9 +417,11 @@ export function reducer(state: TreeState, action: Action): TreeState {
417
417
} ,
418
418
} ) ;
419
419
}
420
+
421
+ return state ;
420
422
}
421
423
case "SELECT_LAST_VISIBLE_NODE" : {
422
- const node = lastVisibleNode ( state . tree , state . nodes ) ;
424
+ const node = lastVisibleNode ( state . tree , state . filteredNodes ) ;
423
425
if ( node ) {
424
426
return reducer ( state , {
425
427
type : "SELECT_NODE" ,
@@ -430,6 +432,8 @@ export function reducer(state: TreeState, action: Action): TreeState {
430
432
} ,
431
433
} ) ;
432
434
}
435
+
436
+ return state ;
433
437
}
434
438
case "SELECT_NEXT_VISIBLE_NODE" : {
435
439
const selected = selectedIdFromState ( state . nodes ) ;
@@ -443,7 +447,7 @@ export function reducer(state: TreeState, action: Action): TreeState {
443
447
} ) ;
444
448
}
445
449
446
- const visible = visibleNodes ( state . tree , state . nodes ) ;
450
+ const visible = visibleNodes ( state . tree , state . filteredNodes ) ;
447
451
const selectedIndex = visible . findIndex ( ( node ) => node . id === selected ) ;
448
452
const nextNode = visible [ selectedIndex + 1 ] ;
449
453
if ( nextNode ) {
@@ -456,6 +460,8 @@ export function reducer(state: TreeState, action: Action): TreeState {
456
460
} ,
457
461
} ) ;
458
462
}
463
+
464
+ return state ;
459
465
}
460
466
case "SELECT_PREVIOUS_VISIBLE_NODE" : {
461
467
const selected = selectedIdFromState ( state . nodes ) ;
@@ -470,9 +476,9 @@ export function reducer(state: TreeState, action: Action): TreeState {
470
476
} ) ;
471
477
}
472
478
473
- const visible = visibleNodes ( state . tree , state . nodes ) ;
479
+ const visible = visibleNodes ( state . tree , state . filteredNodes ) ;
474
480
const selectedIndex = visible . findIndex ( ( node ) => node . id === selected ) ;
475
- const previousNode = visible [ selectedIndex - 1 ] ;
481
+ const previousNode = visible [ Math . max ( 0 , selectedIndex - 1 ) ] ;
476
482
if ( previousNode ) {
477
483
return reducer ( state , {
478
484
type : "SELECT_NODE" ,
0 commit comments