fix(web): reset command palette selection when the result list changes#1265
Open
abhay-codes07 wants to merge 1 commit into
Open
fix(web): reset command palette selection when the result list changes#1265abhay-codes07 wants to merge 1 commit into
abhay-codes07 wants to merge 1 commit into
Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The documents command palette keeps a
selectedIndexinto its item list, and the effect commented "Reset selection on items change" has an empty dependency array — so it only ever runs on mount:Arrow down to row 5 of the recent-documents list, then type a query that returns two results:
selectedIndexstays 5, the highlight disappears (no row rendersdata-index="5"), and Enter silently does nothing becauseitems[5]isundefined. 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:
Clamping rather than always resetting keeps the cursor position stable when the list merely refreshes without shrinking.
Testing
bun testinapps/web— 37 passbun run buildinapps/web— cleanbiome checkon the touched file — clean (the one remaining warning aboutitemsinhandleKeyDowndeps predates this change)