fix: speed up fff file search (#31366)
This commit is contained in:
@@ -240,6 +240,7 @@ export const LineCommentEditor = (props: LineCommentEditorProps) => {
|
||||
},
|
||||
key: (item) => item.path,
|
||||
filterKeys: ["path"],
|
||||
skipFilter: () => true,
|
||||
onSelect: selectMention,
|
||||
})
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user