File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 11import { memo , useCallback } from 'react'
22import type { DisplayResult } from '../../../types'
33import TreeItem from './TreeItem'
4+ import { refScroller } from './useListState'
45import * as stylex from '@stylexjs/stylex'
56import { 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 }
Original file line number Diff line number Diff line change 44import { useCallback } from 'react'
55import { useBoolean } from 'react-use'
66import { 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
815const 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
Original file line number Diff line number Diff 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
5458function 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
You can’t perform that action at this time.
0 commit comments