11import { BRANCH_NODE } from '@lcov-viewer/core' ;
2- import { collapseRow , expandRow , hideRow , showRow } from '../render/collapse' ;
32import { useEffect , useRef } from 'react' ;
3+ import { collapseRow , expandRow , hideRow , showRow } from '../render/collapse' ;
44
55const findRow = ( element ) => {
66 let current = element ;
@@ -12,6 +12,8 @@ const findRow = (element) => {
1212 return current ;
1313} ;
1414
15+ const makeParentPath = path => path && `${ path } /` ;
16+
1517const useCollapse = ( ) => {
1618 const ref = useRef ( ) ;
1719 const state = useRef ( { } ) ;
@@ -41,11 +43,12 @@ const useCollapse = () => {
4143 } else {
4244 collapseRow ( rowState . row ) ;
4345 }
44-
45- const childrenPaths = Object . keys ( state . current ) . filter ( path => path . startsWith ( rowState . path ) && path !== rowState . path ) ;
46+
47+ const childrenPaths = Object . keys ( state . current ) . filter ( path => path . startsWith ( makeParentPath ( rowState . path ) ) && path !== rowState . path ) ;
4648 const collapsedChildrenPaths = childrenPaths . filter ( path => state . current [ path ] . collapsed ) ;
4749 const affectedChildrenPaths = childrenPaths
48- . filter ( path => ! collapsedChildrenPaths . find ( collapsedChildPath => path . startsWith ( collapsedChildPath ) && path !== collapsedChildPath ) ) ;
50+ . filter ( path => ! collapsedChildrenPaths
51+ . find ( collapsedChildPath => path . startsWith ( makeParentPath ( collapsedChildPath ) ) && path !== collapsedChildPath ) ) ;
4952
5053 affectedChildrenPaths . forEach ( path => {
5154 if ( rowState . collapsed ) {
0 commit comments