Skip to content

#869 Keyboard and mouse support - #928

Merged
ivanfenenko merged 5 commits into
mainfrom
feature/869-keyboard-mouse-support
Nov 3, 2026
Merged

ivanfenenko merged 5 commits into
mainfrom
feature/869-keyboard-mouse-support

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #869

Keyboard and mouse support for iPad, Android tablets and Chromebooks, one commit per tier.

Tier 1, both platforms:

  • Design-system controls take keyboard focus and draw one focus ring, only for keyboard focus (never after a touch).
  • Tab order and arrow groups on Home, Session Chat, Settings, sheets and dialogs. Return or Space activates. Sheets keep Tab inside and give focus back to the control that opened them.
  • Permission and question prompts arrive with nothing focused, so a stray Return, Space or letter cannot answer them, including when one queued request replaces another. The first Tab enters at the first enabled control (Deny on permissions). "Press Tab to answer with the keyboard" shows while a hardware keyboard is connected.
  • With a hardware keyboard, Return sends and Shift+Return adds a line. Return reads the live text, and does nothing while the @ / / list is open or IME text is composing. Soft keyboards are unchanged.
  • Esc: close the top sheet or dialog → leave focus → arm interrupt ("Esc again to interrupt") → a second Esc within 5 s stops the turn, matching the TUI.
  • New OpenCodeKeyboardHint design-system component.

Tier 2, both platforms (Android uses Ctrl where iPad uses ⌘):

  • App shortcuts: New Session ⌘N, Command Palette ⌘K, Choose Model ⌘⇧M, Settings ⌘, and Show ‹project› ⌘1–9. ⌘N replaces the iPad New Window command and creates the session in the open chat's project, also from a subagent session.
  • Prompt shortcuts: ⌘⏎ Allow Once / Next Question / Submit Answers, ⌥⌘⏎ Always Allow, ⌘⌫ Deny / Dismiss Question. They follow the same rules as the buttons and never repeat while held. In "Type your own answer", ⌘⌫ keeps deleting text.
  • Bare 1–9 picks a question option once focus is inside the prompt (never with modifiers or in a text field).
  • ↑ in an empty composer recalls this session's sent prompts, ↓ goes forward; in a multi-line recall only from the first or last line.
  • Listed in the iPad menu bar and hold-⌘ overlay, and in the Android Keyboard Shortcuts Helper.
  • Right-click opens the long-press actions on messages, list rows and the session dock, and a Remove menu on projects. Right-click never presses a plain control.
  • Hover feedback in design-system controls, pointer only.

Tier 3:

Platform differences:

  • Android: when nothing else uses Esc, it acts as Back. iOS does nothing there (iPadOS has no Esc-to-go-back convention).
  • iOS: SwiftUI cannot move focus programmatically from "nothing focused", so arrows cannot enter a prompt; the first Tab does. After Return/Esc in "Type your own answer", the next Tab reaches Next/Submit rather than focus moving there by itself.
  • iPad keeps New Session and Settings in the system File and app menus; Android groups shortcuts as Session, Prompt and Go. Titles match.

Checks

  • iOS and Android both covered
  • Screenshots for UI changes (attached in comments, one per tier)
  • Tests run
    • iOS unit tests: 3,176 passed through Tier 2; Tier 3's one-line iOS change ran the related suites (151 passed). Full suites run in CI.
    • Android testDebugUnitTest: 3,228 run, 3 failures unrelated to this change. Two expect 2.5s and fail on a decimal-comma locale; SseRecoveryFaultOracleTest also fails on main.
  • Verified on an iPad simulator and a tablet-size Android emulator against the scenario harness, with hardware key and mouse events. Tier 1 and Android Tier 2 ran against a v2 server; iOS Tier 2 from the permission shortcuts on, and Tier 3 on both platforms, ran against a classic v1 server.

Risks / Follow-ups

  • iOS split view: Tab follows screen position, so it mixes sidebar and detail pane.
  • Queued prompt replacement (one request replacing another while focused) is unit-tested on both platforms, but the harness could not queue two requests on a device.
  • iOS hover: the simulator does not render hover from scripted pointer moves; needs a real iPad with a pointer.
  • Android: five feature-local tappable views outside the design system (Servers screen, retry countdown, failure banner, pending prompts sheet, connection setup fields) still treat a right-click as a click.
  • Android: Ctrl+N does nothing while Files or Changes is pushed over the chat in the split pane. Ctrl+N from a subagent session was not checked on device (iOS was).
  • Not checked: Tier 1 on a classic v1 server on device, real hardware keyboards and mice (double-click word selection), ChromeOS, Japanese IME on device, iOS Full Keyboard Access.
  • Accepted drops were checked with a temporary change, because the harness models take no attachments.
  • iOS full-screen covers (add project, connection setup) and system share sheets keep their own Esc behaviour.

@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Tier 1 evidence

iPad simulator and tablet-size Android emulator against the scenario harness, driven with hardware key events.

Step iOS Android
Home: focus ring on a session row iOS Home focus Android Home focus
Session Chat: focus on a control iOS Session Chat focus Android Session Chat focus
Question arrives: nothing focused, Tab hint iOS question hint Android question hint
First Tab: option focused iOS question option focus Android question option focus
Permission arrives: nothing focused, Tab hint iOS permission hint Android permission hint
Permission: button focused iOS permission button focus Android permission button focus
First Esc while busy: "Esc again to interrupt" iOS Esc armed Android Esc armed
Second Esc: turn interrupted iOS interrupted Android interrupted
Settings: row focused iOS Settings focus Android Settings focus
Sheet: Tab stays inside iOS sheet focus Android sheet focus
Sheet closed: focus back on the opener iOS focus restored Android focus restored
Focus ring on a dark button iOS ring on dark button Android ring on dark button

@ivanfenenko
ivanfenenko marked this pull request as ready for review November 1, 2026 21:20
@ivanfenenko
ivanfenenko force-pushed the feature/869-keyboard-mouse-support branch 2 times, most recently from 26b6519 to 7d994a5 Compare November 1, 2026 21:58
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Tier 2 evidence

iPad simulator (shots 01–08 against a v2 server, 09–18 against a classic v1 server) and a tablet-size Android emulator (v2 server), driven with hardware key and mouse events. Android uses Ctrl where iPad uses ⌘.

Shortcut lists

iPad menu bar Android Keyboard Shortcuts Helper
iPad File menu with New Session Android helper, Session and Go groups
iPad Session menu Android helper with Prompt group
iPad Prompt menu
iPad Go menu
iPad app menu with Settings

Keyboard

Step iOS Android
⌘K: Command Palette iOS command palette Android command palette
⌘⇧M: Choose Model iOS model picker Android model picker
Permission before ⌘⏎ iOS permission before Android permission before
After ⌘⏎: allowed once iOS permission after Android permission after
Digit picks a question option iOS digit pick Android digit pick on a scrolling question
↑ recalls a sent prompt iOS recalled prompt Android recalled prompt
⌘⌫ in "Type your own answer" deletes text iOS custom answer delete
Multi-line recall iOS multi-line recall
⌘N from a subagent session iOS new session from child

Mouse

Step iOS Android
Right-click a session row iOS session row menu Android session row menu
Right-click a project: Remove iOS project Remove menu Android project Remove menu
Right-click a sent message iOS message actions Android message actions
Right-click an assistant message Android assistant message actions
Right-click Allow Once / Deny does nothing iOS right-click on prompt buttons
Hover not rendered by the simulator Android hover on New session Android hover on a session row

@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Tier 3 evidence

Pointer checks on an iPad simulator (classic v1 server) and a tablet-size Android emulator (classic v1 server). The harness models accept no attachments, so drops are declined there; the accepted path was checked with a temporary change that turned drops on (reverted, marked "debug" below).

Text selection and copy with a pointer

Step iOS Android
Assistant message: drag-select long-press / right-click → Copy (not touch-selectable on iOS) iOS message Copy actions Android assistant text selected
Copied text pasted into the prompt Android copy pasted
Code block Android code block selected
Tool output: drag-select, right-click Copy iOS tool result selection Android tool output selected
Click clears the selection iOS selection cleared
Shell output: drag-select, right-click Copy iOS shell output selection

Drag and drop onto the composer

Step iOS Android
Image, drops off for this model iOS image declined
Text file, drops off: goes into the prompt as text iOS text into prompt
Debug: image shows "Can't attach this" iOS image reject card Android image reject card
Debug: card stays after release (iOS, #951) iOS reject card stays
Debug: text file "Drop to attach" iOS accept card
Debug: text file attached iOS text file attached Android text file attached

@ivanfenenko
ivanfenenko force-pushed the feature/869-keyboard-mouse-support branch from d8adff1 to 156a337 Compare November 2, 2026 13:17
@ivanfenenko ivanfenenko mentioned this pull request Nov 3, 2026
13 tasks done
ivanfenenko and others added 3 commits November 3, 2026 10:11
Hardware keyboard users on iPad, Android tablets and Chromebooks can drive
the app with standard focus navigation.

- Design-system controls take keyboard focus and draw one focus ring
  (interactive token with a surface hairline), only for keyboard focus.
- Tab order and arrow groups on Home, Session Chat, Settings, sheets and
  dialogs. Return or Space activates. Sheets keep Tab inside and return
  focus to the control that opened them.
- Permission and question prompts arrive with nothing focused, so a stray
  key cannot answer them. The first Tab enters at the first enabled
  control. A "Press Tab to answer with the keyboard" hint shows while a
  hardware keyboard is connected. In "Type your own answer", Return saves
  and Esc leaves the field.
- With a hardware keyboard the composer sends on Return and adds a line on
  Shift+Return, reading the live text. Not while the @ or / list is open
  or IME text is composing. Soft keyboards are unchanged.
- Esc closes the top sheet or dialog, then leaves focus, then arms an
  interrupt ("Esc again to interrupt"); a second Esc within 5 s stops the
  turn, matching the TUI. On Android Esc otherwise acts as Back.
- New OpenCodeKeyboardHint component on both platforms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shortcuts on top of the Tier 1 focus model, plus right-click and hover.
Android uses Ctrl where iPad uses ⌘.

- App: New Session ⌘N, Command Palette ⌘K, Choose Model ⌘⇧M, Settings ⌘,
  and Show <project> ⌘1–9. ⌘N replaces the iPad New Window command and
  creates the session in the open chat's project, also from a subagent
  session.
- Prompts: ⌘⏎ Allow Once / Next Question / Submit Answers, ⌥⌘⏎ Always
  Allow, ⌘⌫ Deny / Dismiss Question. They act on the visible request with
  the same rules as the buttons and never repeat while held. In "Type your
  own answer" ⌘⌫ keeps deleting text.
- Bare 1–9 picks a question option once focus is inside the prompt, never
  with modifiers or in a text field.
- ↑ in an empty composer steps back through this session's sent prompts,
  ↓ forward; in a multi-line recall only from the first or last line.
- Listed in the iPad menu bar and hold-⌘ overlay, and in the Android
  Keyboard Shortcuts Helper.
- Right-click opens the long-press actions on messages, list rows and the
  session dock, and a Remove menu on projects. Right-click no longer
  presses plain controls.
- Hover feedback in design-system controls, pointer only.

Search sessions (⌘F) moved to #929.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Android declares the touchscreen optional, so Play can list the app on
  Chromebooks without one.
- Android: a mouse click on message text only places or clears the text
  selection; right-click opens message actions. Touch is unchanged.
- iOS: right-click opens message actions on assistant messages without
  markdown, as it already did on markdown messages.

Checked with a pointer on both platforms: dropping files onto the composer
(#870) and selecting and copying text in messages, code blocks and tool
output wherever touch can select. Deny with a note moved to #946; the iOS
declined-drop card is tracked in #951.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko force-pushed the feature/869-keyboard-mouse-support branch from 156a337 to d126024 Compare November 3, 2026 09:34
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor reivew

@cursor

cursor Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Posted a review on #928. The shared rule tables, prompt-chord gating, and evidence look solid; the problems are in state that outlives the UI and in a few pointer handlers that ignore consumption.

Would not merge until these three are fixed:

  • iOS Esc hold — UIKeyCommand repeats by default, so one hold can arm and interrupt. Android already swallows key-repeat.
  • iOS first Tab into a prompt — a leftover nextTabTarget (Tab-out of the composer, or a closed sheet) beats promptEntry, so Tab can miss Deny entirely.
  • Android session dock — right-click still opens the project picker because the gesture uses requireUnconsumed = false after the swallow.

Also worth fixing: Android only parks composer focus when a prompt arrives (sidebar/timeline focus stays live); Tab auto-repeat after prompt entry can walk onto Always; iOS’s 0.6s chord window drops a second Cmd+Return on a queued permission; several Android design-system pills still treat right-click as click.

Open in Web Open in Cursor 

@cursor

cursor Bot commented Nov 3, 2026

Copy link
Copy Markdown

Review

The shared rule tables, prompt-chord gating, and evidence are in good shape. CI is green. The problems I found are in state that outlives the UI and in a few pointer handlers that ignore consumption. None of these showed up in the unit tests that only exercise the pure functions.

High

1. iOS: holding Esc can arm and interrupt in one press

OpenCodeEscapeResolver is a two-press policy (and Android’s host swallows repeatCount > 0). The iOS Esc UIKeyCommands never set repeats = false, and handleEscape() does not debounce. Default UIKeyCommand.repeats is true, so a hold is: arm → repeat within 5s → interrupt.

        private static let escapeCommand: UIKeyCommand = {
            let command = UIKeyCommand(
                input: UIKeyCommand.inputEscape,
                modifierFlags: [],
                action: #selector(openCodeAnchorEscape(_:))
            )
            command.wantsPriorityOverSystemBehavior = true
            return command
        }()

Same on the root-VC and overlay commands. Return/Space on controls already use phases: .down so they do not repeat; Esc should match. Set repeats = false (and/or ignore repeats in the router).

2. iOS: stale nextTabTarget can make the first Tab miss the prompt

OpenCodeTabRestriction.target always prefers nextTabTarget over promptEntry. It is only cleared when some control actually takes focus. Prompt arrival (clearFocusForArrivingPrompt) parks on the anchor and never invalidates it.

After Tab-out of the composer (setNextTabTarget(.afterPrompt)) or closing a sheet (opener restored), a permission can replace the composer. The restriction then points at a key that is gone, so isTabStop is false for every control and Tab does not enter Deny. Cmd+Return still works; the Tier 1 Tab path does not.

Prompt arrival (and overlay close when the opener is gone) should drop nextTabTarget when it is no longer a live Tab stop, so promptEntry can win.

3. Android: session-dock scope opens on right-click

openCodeSwallowSecondaryPress consumes the press, then the dock’s own pointerInput does awaitFirstDown(requireUnconsumed = false) and treats a non-drag as onOpen(). Swallow only helps handlers that honor consumption.

                .pointerInput(shownTabId, isSwitching) {
                    awaitEachGesture {
                        val down = awaitFirstDown(requireUnconsumed = false)
                        // ...
                        if (!dragged) {
                            latestOnOpen()

Require an unconsumed primary press, or ignore isSecondaryPressed.

Medium

4. Android: “nothing focused when a prompt appears” only parks composer subtree focus

parksFocusOnPromptChange is composerHasFocus && new prompt id. If a session row, timeline control, or Home sidebar holds focus, arrival does not park. Then entersPrompt sees focusHeld and the first Tab/arrow does not enter; Return/Space still activates the outside control. Stray keys still cannot answer the prompt, but the arrival invariant and “first Tab enters” fail whenever focus was outside the composer.

Park window focus on every new prompt id, not only when the composer subtree already has it.

5. Android: Tab/arrow auto-repeat after prompt entry walks to the next button

Esc swallows repeatCount > 0. Prompt entry does not. First Tab focuses Deny and sets windowFocusHeld; the next auto-repeat (~400ms) falls through to dispatchToViews() and Compose moves to Always. Holding Tab then Return can Always-allow. Consume repeats of the same key until KEY_UP, the way Esc already does. tabFollowsNormalOrderOnceFocusIsHeld covers a later Tab, not the repeats of the entry press.

6. iOS: 0.6s chord window also rate-limits a second deliberate press

OpenCodeShortcutRepeatGuard (and firesNow recording lastAttempts even when allowsNow fails) is a refractory period, not “only while held”. Cmd+Return on request A, then a queued permission, then Cmd+Return again within 0.6s is dropped. The comment says this is how you suppress hold-repeat; key-up / repeats = false would not block a new press. This is the queued-replacement path the PR calls out.

7. Android: several design-system controls still treat right-click as click

openCodeControl swallows secondary press, but these never go through it: OpenCodeActionPill, OpenCodeReviewChangesPill, OpenCodeSessionStatusBar, segmented OpenCodeFilterTabs, OpenCodeTaskRow, OpenCodeHunkNavigationPill. iOS peers get openCodeIgnoresSecondaryClick from openCodeKeyboardFocusable. Feature-local gaps in the PR body are separate; these are design-system.

Related: OpenCodeReorderableList only attaches openCodeSecondaryClick when canReveal (e.g. unpinned). A right-click on a pinned Home row still goes through awaitFirstDown() and can select.

8. Right-click on a code block never offers “Copy code block”

Both platforms always open text actions on secondary click, even over a fence. Touch tap on a code block still passes CodeBlock.

What’s solid

  • Prompt chords: same path as the buttons; Custom Answer keeps Ctrl/⌘+Backspace for delete; digits gated on focus-inside-prompt and no modifiers.
  • Android Esc priority and hold-repeat tests; parked focus root so a stray Return cannot hit Home.
  • Composer Return vs Shift+Return, IME pass-through, and @// blocking send (the list itself still does not confirm on Return — fine for the written acceptance).
  • iOS Cmd+N replacing New Window and creating in the open chat’s project, including a subagent route (unit-tested).
  • Manifest touchscreen required=false is the right Play declaration.
  • Android mouse left-click on message text is selection-only; touch tap/long-press unchanged.

Test gaps that hid the above

  • Host: Tab/arrow repeatCount > 0 immediately after a successful prompt enter.
  • Prompt arrival with windowFocusHeld / nextTabTarget still set.
  • iOS Esc UIKeyCommand repeat (or a router-level repeat guard with a test).
  • Two successful firesNow(.promptPrimary) < 0.6s apart after a real allow.
  • Pointer: dock requireUnconsumed = false vs swallow.

I would not merge until 1–3 are fixed. 4–6 are the next keyboard-safety misses; 7–8 are the right-click contract. The rest of the PR (rule split, both-protocol events untouched, evidence) looks mergeable once those land.

Keyboard:
- iOS: a held Esc arms the interrupt once and never interrupts. UIKit
  cannot stop a key command repeating, so Esc and menu chords share a
  guard that holds a key until it goes up (or a 0.6 s pause).
- iOS: a second deliberate Cmd+Return on a queued permission fires; a
  held one still fires once.
- iOS: a Tab target handed over to a control that is gone (Tab out of
  the composer, a closed sheet's opener) is dropped, and a new prompt
  clears it, so the first Tab enters the prompt.
- Android: focus is parked on every new prompt wherever it was, unless
  another text field is being typed in or a sheet is open.
- Android: repeats of the Tab or arrow that entered a prompt are
  swallowed until the key goes up.

Pointer:
- Android: right-click no longer opens the session dock's scope picker,
  presses the action, review-changes, status, filter-tab, task-row or
  hunk-navigation controls, or selects a pinned list row.
- Both: right-click on a code or diff block offers Copy code block, like
  a tap on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Review fixes

Addressed all eight points from the review in 7752f6a.

High

  1. iOS: held Esc arms and interrupts. UIKit has no way to stop a UIKeyCommand from repeating (there is no repeats property on iOS). Instead, OpenCodeEscapeRouter.handleEscape() now goes through a repeat guard: Esc stays held until a hardware key goes up (from the GameController key observer the focus state already uses). A hold arms once and never interrupts. Esc, release, Esc still interrupts. If no key-up arrives, a 0.6 s pause counts as a release. All three Esc commands now come from one factory.
  2. iOS: a stale nextTabTarget beats the prompt entry. Focusable controls now count themselves in a live Tab-stop registry. A handed-over target that is not on screen is dropped when it is set, and again once its last control goes away (checked on the next turn, so a replacement view with the same key keeps it). Prompt arrival and queued replacement also clear it, so the first Tab enters at Deny.
  3. Android: right-click on the session dock opens the scope picker. The dock's gesture still reads downs with requireUnconsumed = false, so it now checks isSecondaryPress() (a new shared helper next to openCodeSwallowSecondaryPress) and drops secondary gestures.

Medium

  1. Android: prompt arrival parks only composer focus. Focus is now parked on every new prompt id wherever it was (composer, timeline, session list, nowhere). The exceptions are typing in another text field and an open sheet or dialog, matching iOS.
  2. Android: Tab/arrow auto-repeat walks past the entry control. Repeats of the key that entered a prompt are swallowed until it goes up, the same way Esc repeats are.
  3. iOS: the 0.6 s chord window drops a deliberate second ⌘⏎. OpenCodeShortcutRepeatGuard is now OpenCodeKeyRepeatGuard, the same key-up-aware guard as Esc. A held chord still fires once. Release then press fires right away (⌘⏎ on a permission, then ⌘⏎ on the queued one).
  4. Android: design-system controls that treat right-click as click. OpenCodeActionPill, OpenCodeReviewChangesPill, OpenCodeSessionStatusBar, the segmented OpenCodeFilterTabs, OpenCodeTaskRow and the OpenCodeHunkNavigationPill buttons now carry openCodeControl (swallows right-click, plus the hand pointer and focus memory). Rows in OpenCodeReorderableList without actions, such as pinned Home rows, now swallow right-click so it cannot select or lift them.
  5. Right-click on a code block never offers "Copy code block". Android: the message's secondary click reads the code block the press landed on (the gate is now cleared for consumed presses too, so a stale block cannot leak). iOS: code and diff blocks publish their bounds, and the message's right-click picks the block under the pointer (openCodeMessageSecondaryClick).

Tests added

  • iOS: OpenCodeKeyRepeatGuardTests (held repeats, release then press, pause fallback, held Esc arms once), OpenCodeTabStopRegistryTests, root Esc command shape.
  • Android: holdingTheTabThatEnteredAPromptDoesNotWalkPastItsEntry, heldArrowRepeatsGoToViewsWhenTheyDidNotEnterAPrompt, and focusParksWhenANewRequestArrivesWhereverFocusWas with its otherField and surface exceptions.

Not checked on device: these fixes are unit-tested and compiled on both platforms but have not been run on a simulator or emulator. Key-repeat timing, right-click on the dock, pinned rows and code blocks, and Tab after a sheet closes over a replaced opener still need a pass with hardware key and mouse events.

Conflicts came from #886 moving app text to string resources while this
branch added keyboard focus, right-click and new shortcuts on the same
lines. Kept both: main's localised labels with the branch's focus and
secondary-click modifiers.

Keyboard shortcut titles now follow main's resource model on both
platforms, extended to every Tier 2 shortcut: Android titles and group
labels are UiText resolved for the Keyboard Shortcuts Helper; iOS titles,
menu names and prompt-chord titles are LocalizedStringResource. New keys
under keyboard_shortcuts.* on both platforms; the single Sessions group
key is replaced by the Session, Prompt and Go groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko
ivanfenenko merged commit 7892efe into main Nov 3, 2026
@ivanfenenko
ivanfenenko deleted the feature/869-keyboard-mouse-support branch November 3, 2026 17:45
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.

Keyboard and mouse support

1 participant