@@ -5,6 +5,35 @@ import type { SgSearch } from '../../../../types'
55import { CodeBlock } from './CodeBlock'
66import { FileLink } from './FileLink'
77import { VSCodeBadge } from '@vscode/webview-ui-toolkit/react'
8+ import { memo } from 'react'
9+
10+ interface CodeBlockListProps {
11+ matches : SgSearch [ ]
12+ }
13+
14+ const CodeBlockList = memo ( ( { matches } : CodeBlockListProps ) => {
15+ return (
16+ < >
17+ { matches ?. map ( match => {
18+ const { file, range } = match
19+ const { byteOffset } = range
20+ return (
21+ < HStack
22+ w = "100%"
23+ justifyContent = "flex-start"
24+ key = { file + byteOffset . start + byteOffset . end }
25+ _hover = { {
26+ background : 'var(--vscode-list-inactiveSelectionBackground)'
27+ } }
28+ >
29+ < Box w = "20px" />
30+ < CodeBlock match = { match } />
31+ </ HStack >
32+ )
33+ } ) }
34+ </ >
35+ )
36+ } )
837
938interface TreeItemProps {
1039 filePath : string
@@ -49,24 +78,13 @@ const TreeItem = ({ filePath, matches }: TreeItemProps) => {
4978 </ HStack >
5079 </ HStack >
5180
52- < VStack w = "100%" alignItems = "flex-start" gap = "0" >
53- { isExpanded &&
54- matches ?. map ( match => {
55- const { file, range } = match
56- return (
57- < HStack
58- w = "100%"
59- justifyContent = "flex-start"
60- key = { file + range . start . line + range . start . column }
61- _hover = { {
62- background : 'var(--vscode-list-inactiveSelectionBackground)'
63- } }
64- >
65- < Box w = "20px" />
66- < CodeBlock match = { match } />
67- </ HStack >
68- )
69- } ) }
81+ < VStack
82+ w = "100%"
83+ alignItems = "flex-start"
84+ gap = "0"
85+ display = { isExpanded ? 'flex' : 'none' }
86+ >
87+ < CodeBlockList matches = { matches } />
7088 </ VStack >
7189 </ VStack >
7290 )
0 commit comments