mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-20 05:06:31 +00:00
fix(web): reset command palette selection when the result list changes
The effect commented 'Reset selection on items change' had an empty dependency array, so it only ever ran on mount. Arrow down to row 5 of the recent-documents list, then type a query that returns two results: selectedIndex stays 5, no row is highlighted (nothing renders data-index=5), and Enter silently does nothing because items[5] is undefined. The selection also never snaps back to the top result when new results stream in. Snap the selection to the top whenever the query text changes, and clamp it into range whenever the item list shrinks (async search results replacing the recent docs, refetches while the palette is open).
This commit is contained in:
parent
2cebe81512
commit
8db722d76c
1 changed files with 8 additions and 2 deletions
|
|
@ -199,10 +199,16 @@ export function DocumentsCommandPalette({
|
|||
for (const a of actions) items.push(a)
|
||||
}
|
||||
|
||||
// Reset selection on items change
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: search is the trigger — snap the selection back to the top result whenever the query changes
|
||||
useEffect(() => {
|
||||
setSelectedIndex(0)
|
||||
}, [])
|
||||
}, [search])
|
||||
|
||||
// Keep the selection in range when the list shrinks (async results
|
||||
// replacing recent docs, refetches, etc.)
|
||||
useEffect(() => {
|
||||
setSelectedIndex((i) => Math.min(i, Math.max(items.length - 1, 0)))
|
||||
}, [items.length])
|
||||
|
||||
// Scroll selected into view
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue