Skip to content

fix(tui): preserve current selection across list updates - #39774

Merged
kitlangton merged 1 commit into
v2from
session-list-cursor-repro
Jul 31, 2026
Merged

fix(tui): preserve current selection across list updates#39774
kitlangton merged 1 commit into
v2from
session-list-cursor-repro

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Keep a dialog's blue selection attached to its current item when asynchronously loaded options are inserted or reordered.

This fixes the session picker showing the current-session dot on one row while Enter would select a different blue-highlighted row.

Before / After

Before: The session picker rendered cached sessions and selected the current session by numeric index. When the server response replaced that list with more sessions or a different order, the index stayed fixed and silently pointed at another session. The dot still followed the current session ID, so the dot and blue selection diverged.

After: A dialog with a current value reconciles selection by option value across list updates. Reordering the options moves the selected index with the same session, keeping the current marker, blue highlight, and Enter behavior aligned.

How

  • packages/tui/src/ui/dialog-select.tsx treats current selections as value-preserving during option reconciliation and post-layout scrolling.
  • packages/tui/test/cli/tui/dialog-select.test.tsx replaces [first, current, third] with [current, third, first] and verifies Enter still submits current.

Scope

Dialogs without a current item retain their existing index-based reconciliation behavior. Filtering and explicit preserveSelection behavior are unchanged.

Testing

  • bun run typecheck from packages/tui
  • bun run test from packages/tui: 574 passed, 5 skipped
  • Full repository typecheck passed during push
  • OpenCode Drive simulated seven sessions against the latest V2 source checkout, switched from Golf to Charlie, and reopened the picker with the dot and blue selection aligned

Demo

Simulated sessions driven through the real V2 TUI in a PTY using the Drive startup fix in anomalyco/opencode-drive#50. The blue selection first moves independently while Golf remains current; after switching to Charlie and reopening, the dot and selection are aligned on Charlie.

session-picker-selection-fix.mp4

Flow

sequenceDiagram
  participant User
  participant SessionPicker
  participant DialogSelect
  participant Server
  User->>SessionPicker: open session list
  SessionPicker->>DialogSelect: current session ID + cached options
  Server-->>SessionPicker: refreshed options
  SessionPicker->>DialogSelect: replace/reorder options
  DialogSelect->>DialogSelect: find selected session by value
  DialogSelect-->>User: dot, highlight, and Enter target stay aligned
Loading

@kitlangton
kitlangton enabled auto-merge (squash) July 31, 2026 00:29
@kitlangton
kitlangton merged commit 865f512 into v2 Jul 31, 2026
15 of 17 checks passed
@kitlangton
kitlangton deleted the session-list-cursor-repro branch July 31, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant