Skip to content

fix(web): reset command palette selection when the result list changes#1265

Open
abhay-codes07 wants to merge 1 commit into
supermemoryai:mainfrom
abhay-codes07:fix/command-palette-selection-reset
Open

fix(web): reset command palette selection when the result list changes#1265
abhay-codes07 wants to merge 1 commit into
supermemoryai:mainfrom
abhay-codes07:fix/command-palette-selection-reset

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

What

The documents command palette keeps a selectedIndex into its item list, and the effect commented "Reset selection on items change" has an empty dependency array — so it only ever runs on mount:

// Reset selection on items change
useEffect(() => {
    setSelectedIndex(0)
}, [])

Arrow down to row 5 of the recent-documents list, then type a query that returns two results: selectedIndex stays 5, the highlight disappears (no row 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 fresh results stream in.

Fix

Two small effects that match the comment's intent:

  • snap the selection to the top whenever the query text changes
  • clamp it into range whenever the item list shrinks (async search results replacing the recent docs, refetches while the palette is open)

Clamping rather than always resetting keeps the cursor position stable when the list merely refreshes without shrinking.

Testing

  • bun test in apps/web — 37 pass
  • bun run build in apps/web — clean
  • biome check on the touched file — clean (the one remaining warning about items in handleKeyDown deps predates this change)

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).
Copilot AI review requested due to automatic review settings July 12, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants