@@ -7,7 +7,7 @@ import { AnnotationStore, selectAnnotations } from '../../annotations/annotation
7
7
import { useNavigate } from 'react-router' ;
8
8
import { useAppDispatch , useAppSelector } from '../../../app/hooks' ;
9
9
import { UsageCountStore } from '../../usages/model/UsageCountStore' ;
10
- import { setAllCollapsedInTreeView , setAllExpandedInTreeView } from '../../ui/uiSlice' ;
10
+ import { setAllCollapsedInTreeView , setAllExpandedInTreeView , setExactlyExpandedInTreeView } from '../../ui/uiSlice' ;
11
11
12
12
interface ActionBarProps {
13
13
declaration : PythonDeclaration ;
@@ -21,6 +21,8 @@ export const ActionBar: React.FC<ActionBarProps> = function ({ declaration, pyth
21
21
const navigate = useNavigate ( ) ;
22
22
23
23
const annotations = useAppSelector ( selectAnnotations ) ;
24
+ const isMatched = ( node : PythonDeclaration ) : boolean =>
25
+ pythonFilter . shouldKeepDeclaration ( node , annotations , usages ) ;
24
26
25
27
return (
26
28
< HStack borderTop = { 1 } layerStyle = "subtleBorder" padding = "0.5em 1em" marginTop = { 0 } w = "100%" >
@@ -86,6 +88,14 @@ export const ActionBar: React.FC<ActionBarProps> = function ({ declaration, pyth
86
88
>
87
89
Collapse Selected
88
90
</ Button >
91
+ < Button
92
+ accessKey = "m"
93
+ onClick = { ( ) => {
94
+ dispatch ( setExactlyExpandedInTreeView ( getMatchedNodesAndParents ( pythonPackage , isMatched ) ) ) ;
95
+ } }
96
+ >
97
+ Expand Matched
98
+ </ Button >
89
99
</ HStack >
90
100
) ;
91
101
} ;
@@ -190,3 +200,42 @@ const getDescendants = function (current: PythonDeclaration): string[] {
190
200
}
191
201
return childrenList ;
192
202
} ;
203
+
204
+ const getMatchedNodesAndParents = function (
205
+ pythonPackage : PythonPackage ,
206
+ isMatched : ( declaration : PythonDeclaration ) => boolean ,
207
+ ) : string [ ] {
208
+ return doGetMatchedNodesAndParents ( pythonPackage , isMatched ) . nodesToExpand ;
209
+ } ;
210
+
211
+ interface DoGetMatchedNodesAndParentsResult {
212
+ nodesToExpand : string [ ] ;
213
+ subtreeShouldBeExpanded : boolean ;
214
+ }
215
+
216
+ const doGetMatchedNodesAndParents = function (
217
+ current : PythonDeclaration ,
218
+ isMatched : ( declaration : PythonDeclaration ) => boolean ,
219
+ ) : DoGetMatchedNodesAndParentsResult {
220
+ const nodesToExpand : string [ ] = [ ] ;
221
+ let shouldExpandThisNode = false ;
222
+
223
+ for ( const child of current . children ( ) ) {
224
+ const { nodesToExpand : childrenNodesToExpand , subtreeShouldBeExpanded } = doGetMatchedNodesAndParents (
225
+ child ,
226
+ isMatched ,
227
+ ) ;
228
+
229
+ nodesToExpand . push ( ...childrenNodesToExpand ) ;
230
+ shouldExpandThisNode ||= subtreeShouldBeExpanded ;
231
+ }
232
+
233
+ if ( shouldExpandThisNode ) {
234
+ nodesToExpand . push ( current . pathAsString ( ) ) ;
235
+ }
236
+
237
+ return {
238
+ nodesToExpand,
239
+ subtreeShouldBeExpanded : isMatched ( current ) || shouldExpandThisNode ,
240
+ } ;
241
+ } ;
0 commit comments