Fix model selector not responding to arrow keys#226
Draft
Conversation
The /model command shows the selection overlay but arrow keys had no effect because updateView() unconditionally called tui.setFocus(editor), stealing focus from the VimSelectList overlay. This meant key events were routed to the editor instead of the selector. Guard the setFocus(editor) call so it only fires when no overlay flow (model selection or approval prompt) is active. Fixes #225 Co-authored-by: Virat Singh <virattt@users.noreply.github.com>
|
fix works for me |
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.
Problem
When the user types
/modelto open the model selection menu, the arrow keys (andj/kvim bindings) do not move the selection cursor. The overlay appears correctly but keyboard navigation is broken. (Fixes #225)Root Cause
The
updateView()function insrc/cli.tsunconditionally callstui.setFocus(editor)on every invocation. This steals focus from theVimSelectListoverlay in two scenarios:Slash autocomplete selection path: When the user selects
/modelfrom the slash suggestions,editor.onSlashSelectcallshandleSlashCommand('model')which opens the overlay and focuses the selector — but then immediately callsupdateView(), which moves focus back to the editor.Agent runner updates: The agent runner's
onChangecallback callsupdateView()on every event while processing, which would steal focus from any open overlay mid-query.Since pi-tui's
SelectListonly receives key events when it has focus, arrow keys are routed to theCustomEditorinstead and never reach the model/provider selector.Fix
Guard the
tui.setFocus(editor)call inupdateView()so it only fires when no overlay flow is active:This ensures focus remains on the overlay's selector component (for model selection, provider selection, and approval prompts) and is only returned to the editor when the overlay is dismissed.
Testing
bun run typecheckpassesbun testpasses (37/37 tests)