Skip to content

Fix model selector not responding to arrow keys#226

Draft
virattt wants to merge 1 commit intomainfrom
cursor/issue-225-model-selector-5dc3
Draft

Fix model selector not responding to arrow keys#226
virattt wants to merge 1 commit intomainfrom
cursor/issue-225-model-selector-5dc3

Conversation

@virattt
Copy link
Copy Markdown
Owner

@virattt virattt commented Apr 5, 2026

Problem

When the user types /model to open the model selection menu, the arrow keys (and j/k vim bindings) do not move the selection cursor. The overlay appears correctly but keyboard navigation is broken. (Fixes #225)

Root Cause

The updateView() function in src/cli.ts unconditionally calls tui.setFocus(editor) on every invocation. This steals focus from the VimSelectList overlay in two scenarios:

  1. Slash autocomplete selection path: When the user selects /model from the slash suggestions, editor.onSlashSelect calls handleSlashCommand('model') which opens the overlay and focuses the selector — but then immediately calls updateView(), which moves focus back to the editor.

  2. Agent runner updates: The agent runner's onChange callback calls updateView() on every event while processing, which would steal focus from any open overlay mid-query.

Since pi-tui's SelectList only receives key events when it has focus, arrow keys are routed to the CustomEditor instead and never reach the model/provider selector.

Fix

Guard the tui.setFocus(editor) call in updateView() so it only fires when no overlay flow is active:

if (!modelSelection.isInSelectionFlow() && !agentRunner.pendingApproval) {
  tui.setFocus(editor);
}

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 typecheck passes
  • bun test passes (37/37 tests)
Open in Web Open in Cursor 

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>
Copy link
Copy Markdown
Contributor

@swrzalek swrzalek left a comment

Choose a reason for hiding this comment

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

lgtm

@guiu-rocafort
Copy link
Copy Markdown

fix works for me

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.

Model selection is not working properly

4 participants