diff options
| author | Adam <[email protected]> | 2025-12-10 21:16:50 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-12-11 06:48:58 -0600 |
| commit | 3bb546c94d6bb295bfeafdafbb9d34b7cc462560 (patch) | |
| tree | 54ae4fa1b18c68d23ff460caab596e942593a857 /packages/ui/src/hooks | |
| parent | 8e15bcb68e9a8a37bb12afca3984f3967ccb58eb (diff) | |
| download | opencode-3bb546c94d6bb295bfeafdafbb9d34b7cc462560.tar.gz opencode-3bb546c94d6bb295bfeafdafbb9d34b7cc462560.zip | |
wip(desktop): progress
Diffstat (limited to 'packages/ui/src/hooks')
| -rw-r--r-- | packages/ui/src/hooks/use-filtered-list.tsx | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/packages/ui/src/hooks/use-filtered-list.tsx b/packages/ui/src/hooks/use-filtered-list.tsx index e0cb6e7aa..f9745918a 100644 --- a/packages/ui/src/hooks/use-filtered-list.tsx +++ b/packages/ui/src/hooks/use-filtered-list.tsx @@ -12,7 +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 - onSelect?: (value: T | undefined) => void + onSelect?: (value: T | undefined, index: number) => void } export function useFilteredList<T>(props: FilteredListProps<T>) { @@ -63,8 +63,9 @@ export function useFilteredList<T>(props: FilteredListProps<T>) { const onKeyDown = (event: KeyboardEvent) => { if (event.key === "Enter") { event.preventDefault() - const selected = flat().find((x) => props.key(x) === list.active()) - if (selected) props.onSelect?.(selected) + const selectedIndex = flat().findIndex((x) => props.key(x) === list.active()) + const selected = flat()[selectedIndex] + if (selected) props.onSelect?.(selected, selectedIndex) } else { list.onKeyDown(event) } |
