Skip to content

Commit c754b9f

Browse files
feat: support virtual scroll
fix #153
1 parent f75cd5c commit c754b9f

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"react-dom": "18.2.0",
137137
"react-icons": "5.0.1",
138138
"react-use": "17.5.0",
139+
"react-virtuoso": "4.7.2",
139140
"tslib": "2.6.2",
140141
"tsx": "4.7.1",
141142
"typescript": "5.4.2",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/webview/SearchSidebar/SearchResultList/Actions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const styles = stylex.create({
1717
flexDirection: 'row',
1818
// see https://github.com/facebook/stylex/issues/373
1919
width: '0',
20+
overflow: 'hidden',
2021
},
2122
action: {
2223
display: 'flex',

src/webview/SearchSidebar/SearchResultList/TreeItem.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ function useStickyShadow() {
4747
}
4848

4949
interface TreeItemProps {
50-
filePath: string
50+
className: string
5151
matches: DisplayResult[]
5252
}
5353

54-
const TreeItem = ({ filePath, matches }: TreeItemProps) => {
54+
const TreeItem = ({ className, matches }: TreeItemProps) => {
5555
const [isExpanded, toggleIsExpanded] = useBoolean(true)
5656
const { isScrolled, ref } = useStickyShadow()
57+
const props = stylex.props(styles.treeItem)
5758

5859
return (
59-
<div {...stylex.props(styles.treeItem)}>
60+
<div className={`${className} ${props.className}`} style={props.style}>
6061
<div className="scroll-observer" ref={ref} />
6162
<TreeHeader
6263
isExpanded={isExpanded}

src/webview/SearchSidebar/SearchResultList/index.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { memo } from 'react'
1+
import { memo, useCallback } from 'react'
22
import { DisplayResult } from '../../../types'
33
import TreeItem from './TreeItem'
44
import * as stylex from '@stylexjs/stylex'
5+
import { Virtuoso } from 'react-virtuoso'
56

67
const styles = stylex.create({
78
resultList: {
89
flexGrow: 1,
910
overflowY: 'scroll',
10-
':not(:hover) > div::before': {
11+
':not(:hover) .sg-match-tree-item::before': {
1112
opacity: 0,
1213
},
13-
':hover > div::before': {
14+
':hover .sg-match-tree-item::before': {
1415
opacity: 1,
1516
},
1617
},
@@ -21,12 +22,25 @@ interface SearchResultListProps {
2122
}
2223

2324
const SearchResultList = ({ matches }: SearchResultListProps) => {
25+
const render = useCallback(
26+
(index: number) => {
27+
const [filePath, match] = matches[index]
28+
return (
29+
<TreeItem
30+
className={'sg-match-tree-item'}
31+
matches={match}
32+
key={filePath}
33+
/>
34+
)
35+
},
36+
[matches],
37+
)
2438
return (
25-
<div {...stylex.props(styles.resultList)}>
26-
{matches.map(([filePath, match]) => {
27-
return <TreeItem filePath={filePath} matches={match} key={filePath} />
28-
})}
29-
</div>
39+
<Virtuoso
40+
{...stylex.props(styles.resultList)}
41+
totalCount={matches.length}
42+
itemContent={render}
43+
/>
3044
)
3145
}
3246

0 commit comments

Comments
 (0)