@@ -48,14 +48,44 @@ export function* filterNode(
48
48
) {
49
49
const treeNodes = new Set < string > ( )
50
50
51
+ const parentsMap = new Map < string , boolean > ( )
51
52
const list : FilterResult [ ] = [ ]
52
53
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
+ }
59
89
}
60
90
61
91
const filesToShow = new Set < string > ( )
@@ -65,6 +95,7 @@ export function* filterNode(
65
95
filter . onlyTests ,
66
96
treeNodes ,
67
97
filesToShow ,
98
+ fileId ,
68
99
) ] . reverse ( )
69
100
70
101
// We show only the files and parents whose parent is expanded.
@@ -129,10 +160,28 @@ function* filterParents(
129
160
collapseParents : boolean ,
130
161
treeNodes : Set < string > ,
131
162
filesToShow : Set < string > ,
163
+ nodeId ?: string ,
132
164
) {
133
165
for ( let i = list . length - 1 ; i >= 0 ; i -- ) {
134
166
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 ) {
136
185
const node = expandCollapseNode (
137
186
match ,
138
187
child ,
0 commit comments