fix: speed up fff file search (#31366)

This commit is contained in:
Shoubhit Dash 2026-06-08 19:09:55 +05:30 committed by GitHub
commit b1a6c40ad0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 68 additions and 39 deletions

View file

@ -240,6 +240,7 @@ export const LineCommentEditor = (props: LineCommentEditorProps) => {
},
key: (item) => item.path,
filterKeys: ["path"],
skipFilter: () => true,
onSelect: selectMention,
})

View file

@ -12,6 +12,7 @@ export interface FilteredListProps<T> {
groupBy?: (x: T) => string
sortBy?: (a: T, b: T) => number
sortGroupsBy?: (a: { category: string; items: T[] }, b: { category: string; items: T[] }) => number
skipFilter?: (item: T) => boolean
onSelect?: (value: T | undefined, index: number) => void
noInitialSelection?: boolean
}
@ -35,10 +36,14 @@ export function useFilteredList<T>(props: FilteredListProps<T>) {
all,
(x) => {
if (!needle) return x
if (!props.filterKeys && Array.isArray(x) && x.every((e) => typeof e === "string")) {
return fuzzysort.go(needle, x).map((x) => x.target) as T[]
}
return fuzzysort.go(needle, x, { keys: props.filterKeys! }).map((x) => x.obj)
const skipFilter = props.skipFilter
const filterable = skipFilter ? x.filter((item) => !skipFilter(item)) : x
const skipped = skipFilter ? x.filter(skipFilter) : []
const filtered =
!props.filterKeys && Array.isArray(filterable) && filterable.every((e) => typeof e === "string")
? (fuzzysort.go(needle, filterable).map((x) => x.target) as T[])
: fuzzysort.go(needle, filterable, { keys: props.filterKeys! }).map((x) => x.obj)
return skipped.length ? [...filtered, ...skipped] : filtered
},
groupBy((x) => (props.groupBy ? props.groupBy(x) : "")),
entries(),