@@ -48,14 +48,44 @@ export function* filterNode(
4848) {
4949 const treeNodes = new Set < string > ( )
5050
51+ const parentsMap = new Map < string , boolean > ( )
5152 const list : FilterResult [ ] = [ ]
5253
53- for ( const entry of visitNode (
54- node ,
55- treeNodes ,
56- n => matcher ( n , search , filter ) ,
57- ) ) {
58- list . push ( entry )
54+ let fileId : string | undefined
55+
56+ if ( filter . onlyTests ) {
57+ for ( const [ match , child ] of visitNode (
58+ node ,
59+ treeNodes ,
60+ n => matcher ( n , search , filter ) ,
61+ ) ) {
62+ list . push ( [ match , child ] )
63+ }
64+ }
65+ else {
66+ for ( const [ match , child ] of visitNode (
67+ node ,
68+ treeNodes ,
69+ n => matcher ( n , search , filter ) ,
70+ ) ) {
71+ if ( isParentNode ( child ) ) {
72+ parentsMap . set ( child . id , match )
73+ if ( isFileNode ( child ) ) {
74+ match && ( fileId = child . id )
75+ list . push ( [ match , child ] )
76+ }
77+ else {
78+ list . push ( [ match || parentsMap . get ( child . parentId ) === true , child ] )
79+ }
80+ }
81+ else {
82+ list . push ( [ match || parentsMap . get ( child . parentId ) === true , child ] )
83+ }
84+ }
85+ // when expanding a non-file node
86+ if ( ! fileId && ! isFileNode ( node ) && 'fileId' in node ) {
87+ fileId = node . fileId as string
88+ }
5989 }
6090
6191 const filesToShow = new Set < string > ( )
@@ -65,6 +95,7 @@ export function* filterNode(
6595 filter . onlyTests ,
6696 treeNodes ,
6797 filesToShow ,
98+ fileId ,
6899 ) ] . reverse ( )
69100
70101 // We show only the files and parents whose parent is expanded.
@@ -129,10 +160,28 @@ function* filterParents(
129160 collapseParents : boolean ,
130161 treeNodes : Set < string > ,
131162 filesToShow : Set < string > ,
163+ nodeId ?: string ,
132164) {
133165 for ( let i = list . length - 1 ; i >= 0 ; i -- ) {
134166 const [ match , child ] = list [ i ]
135- if ( isParentNode ( child ) ) {
167+ const isParent = isParentNode ( child )
168+ if ( ! collapseParents && nodeId && treeNodes . has ( nodeId ) && 'fileId' in child && child . fileId === nodeId ) {
169+ if ( isParent ) {
170+ treeNodes . add ( child . id )
171+ }
172+ let parent = explorerTree . nodes . get ( child . parentId )
173+ while ( parent ) {
174+ treeNodes . add ( parent . id )
175+ if ( isFileNode ( parent ) ) {
176+ filesToShow . add ( parent . id )
177+ }
178+ parent = explorerTree . nodes . get ( parent . parentId )
179+ }
180+ yield child
181+ continue
182+ }
183+
184+ if ( isParent ) {
136185 const node = expandCollapseNode (
137186 match ,
138187 child ,
0 commit comments