@@ -386,13 +386,22 @@ function reduceTreeState(store: Store, state: State, action: Action): State {
386386 }
387387 // TODO (inline errors) The element indices are incorrect if the element is hidden in a collapsed tree.
388388 // Shouldn't hidden elements excluded from computing a valid index?
389- const elementIndicesWithErrorsOrWarnings = Array . from (
389+ const elementIndicesWithErrorsOrWarnings : number [ ] = Array . from (
390390 store . errorsAndWarnings . keys ( ) ,
391- elementId => store . getIndexOfElementID ( elementId ) ,
392- ) ;
391+ )
392+ . map ( elementId => {
393+ // $FlowFixMe https://github.com/facebook/flow/issues/1414
394+ return store . getIndexOfElementID ( elementId ) ;
395+ } )
396+ . filter ( elementIndex => {
397+ return elementIndex !== null ;
398+ } ) ;
393399 const predecessors = elementIndicesWithErrorsOrWarnings . filter (
394400 elementIndex => {
395- return elementIndex !== null && elementIndex < selectedElementIndex ;
401+ return (
402+ selectedElementIndex === null ||
403+ elementIndex < selectedElementIndex
404+ ) ;
396405 } ,
397406 ) ;
398407 if ( predecessors . length === 0 ) {
@@ -409,13 +418,22 @@ function reduceTreeState(store: Store, state: State, action: Action): State {
409418 return state ;
410419 }
411420
412- const elementIndicesWithErrorsOrWarnings = Array . from (
421+ const elementIndicesWithErrorsOrWarnings : number [ ] = Array . from (
413422 store . errorsAndWarnings . keys ( ) ,
414- elementId => store . getIndexOfElementID ( elementId ) ,
415- ) ;
423+ )
424+ . map ( elementId => {
425+ // $FlowFixMe https://github.com/facebook/flow/issues/1414
426+ return store . getIndexOfElementID ( elementId ) ;
427+ } )
428+ . filter ( elementIndex => {
429+ return elementIndex !== null ;
430+ } ) ;
416431 const successors = elementIndicesWithErrorsOrWarnings . filter (
417432 elementIndex => {
418- return elementIndex !== null && elementIndex > selectedElementIndex ;
433+ return (
434+ selectedElementIndex === null ||
435+ elementIndex > selectedElementIndex
436+ ) ;
419437 } ,
420438 ) ;
421439 if ( successors . length === 0 ) {
0 commit comments