Skip to content

Commit be6bd52

Browse files
feat: sort result list
1 parent 566575a commit be6bd52

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/webview/SearchSidebar/SearchResultList/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { memo, useCallback } from 'react'
22
import type { DisplayResult } from '../../../types'
33
import TreeItem from './TreeItem'
4+
import { refScroller } from './useListState'
45
import * as stylex from '@stylexjs/stylex'
56
import { Virtuoso } from 'react-virtuoso'
67

@@ -37,6 +38,7 @@ const SearchResultList = ({ matches }: SearchResultListProps) => {
3738
)
3839
return (
3940
<Virtuoso
41+
ref={refScroller}
4042
{...stylex.props(styles.resultList)}
4143
totalCount={matches.length}
4244
itemContent={render}

src/webview/SearchSidebar/SearchResultList/useListState.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
import { useCallback } from 'react'
55
import { useBoolean } from 'react-use'
66
import { onResultChange } from '../../hooks/useSearch'
7+
import type { VirtuosoHandle } from 'react-virtuoso'
8+
9+
let ref: VirtuosoHandle
10+
11+
export function refScroller(handle: VirtuosoHandle) {
12+
ref = handle
13+
}
714

815
const collapseMap = new Map<string, boolean>()
916

@@ -17,7 +24,11 @@ export function useToggleResult(filePath: string) {
1724
const toggleIsExpanded = useCallback(() => {
1825
toggleResult(filePath)
1926
toggle()
20-
}, [filePath, toggle])
27+
if (isExpanded) {
28+
// TODO
29+
// ref.scrollToIndex(10)
30+
}
31+
}, [filePath, toggle, isExpanded])
2132
return [isExpanded, toggleIsExpanded] as const
2233
}
2334

src/webview/hooks/useSearch.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export function onResultChange(f: () => void) {
5050
}
5151
}
5252

53+
function byFileName(a: [string, unknown], b: [string, unknown]) {
54+
return a[0].localeCompare(b[0])
55+
}
56+
5357
// this function is also called in useQuery
5458
function postSearch(searchQuery: SearchQuery) {
5559
id = (id + 1) % MOD
@@ -68,6 +72,7 @@ childPort.onMessage('searchResultStreaming', event => {
6872
refreshResultIfStale()
6973
queryInFlight = query
7074
grouped = merge(groupBy(event.searchResult))
75+
grouped.sort(byFileName)
7176
notify()
7277
})
7378

@@ -104,6 +109,7 @@ childPort.onMessage('refreshSearchResult', event => {
104109
temp.set(fileName, updatedResults)
105110
}
106111
grouped = [...temp.entries()]
112+
grouped.sort(byFileName)
107113
notify()
108114
})
109115

0 commit comments

Comments
 (0)