fix: make sure first autocomplete item is selected #4708
Closed
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.
Context
When the list of autocomplete items is shown for commands or files the first item should always be selected. Currently no item is selected and the arrow keys must be used to select. This fix makes autocomplete quicker to work with and matches how OpenCode works.
Implementation
This actually fixes what looks like a bug -- selecting the first item looks like the intended behavior, but has a subtle issue.
In cli/src/state/hooks/useCommandInput.ts function useCommandInput() suggestions are being set but the order of the calls to set the suggestions are resetting the selected index.
This fix proposes adding updateAllSuggestionsAtom() which takes all suggestion types and determines which one has any items and sets the index accordingly.
How to Test
Start typing "/"
The first command autocomplete item should be selected
Start typing "@"
The first file autocomplete item should be selected