Skip to content

fix(mobile): preserve iPad hardware keyboard focus - #12772

Merged
nwparker merged 3 commits into
stablyai:mainfrom
ramarivera:fix/ipad-hardware-keyboard-terminal-input
Sep 6, 2026
Merged

nwparker merged 3 commits into
stablyai:mainfrom
ramarivera:fix/ipad-hardware-keyboard-terminal-input

Conversation

@ramarivera

@ramarivera ramarivera commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you use Orca on an iPad with a physical keyboard attached, tapping a terminal to type could stop working: the app mistook "no on-screen keyboard" for "you dismissed the keyboard" and reset the hidden typing field, so hardware keystrokes never reached the terminal. That reset trick is now used only where it's needed (Android). On iPad, tapping a terminal keeps the typing field attached, so a physical keyboard just works.

Problem

On iPad with a hardware keyboard attached, the software keyboard height remains zero. The terminal input focus path treated that as a dismissed software keyboard, blurred the already-focused hidden TextInput, and prevented the hardware keyboard from retaining an input responder.

Change

  • Keep the existing blur/refocus workaround on Android only.
  • Preserve the focused terminal input responder on iOS when software-keyboard height is zero.
  • Add focused regression coverage at the primitive and hook seams.

No native iOS project, deployment-target, CocoaPods, build, or compilation configuration changes are included.

Verification

  • pnpm test -- src/terminal/terminal-live-input.test.ts src/terminal/use-terminal-live-input-focus.test.ts
  • Result: 426 test files passed; 3,298 tests passed and 3 skipped.
  • Live device: tested on a physical iPad Pro M5 with a real Apple Magic Keyboard—not a simulator. Hardware keyboard input in Orca terminal windows works with this change.

Fixes #12706

🤖 This content was generated with AI assistance using GPT-5.6 Sol.

Visual Proof

N/A on desktop — mobile-only fix (iPad hardware keyboard focus preservation in the terminal live input). Demonstrating it requires a physical iPad with a hardware keyboard; desktop builds are unaffected.

Copilot AI lite review requested due to automatic review settings August 5, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes terminal live-input focus behavior on iPad when a hardware keyboard is attached (software keyboard height stays 0), preventing the focus path from blurring an already-focused hidden TextInput and thereby preserving the hardware keyboard responder on iOS.

Changes:

  • Gate the “blur then refocus” workaround behind an explicit flag and enable it only on Android.
  • Thread the new reopenFocusedInputWhenKeyboardHidden option through the focus hook into focusTerminalLiveInputTarget.
  • Add regression tests at both the primitive (focusTerminalLiveInputTarget) and hook (useTerminalLiveInputFocus) layers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
mobile/src/terminal/use-terminal-live-input-focus.ts Passes a new focus-behavior flag through the hook to control reopen behavior when keyboard height is zero.
mobile/src/terminal/use-terminal-live-input-focus.test.ts Adds hook-level coverage ensuring iOS/iPad hardware-keyboard scenarios don’t blur an already-focused responder.
mobile/src/terminal/terminal-live-input.ts Updates the focus primitive to conditionally apply the blur/refocus workaround based on the new flag.
mobile/src/terminal/terminal-live-input.test.ts Adds primitive-level regression coverage for the new iPad/hardware keyboard focus behavior.
mobile/app/h/[hostId]/session/[worktreeId].tsx Enables the reopen workaround only on Android by setting the new flag via Platform.OS === 'android'.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 179924c5-1e75-4873-abe9-b5a9cf6f5ca2

📥 Commits

Reviewing files that changed from the base of the PR and between e73f8df and 4f5ae14.

📒 Files selected for processing (6)
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/use-mobile-session-terminal-runtime.ts
  • mobile/src/terminal/terminal-live-input.test.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/src/terminal/use-terminal-live-input-focus.test.ts
  • mobile/src/terminal/use-terminal-live-input-focus.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33cce5b8-2bde-4f1c-9ccc-b1fe06b84470

📥 Commits

Reviewing files that changed from the base of the PR and between 6989c92 and 8807014087bb4565579f25cd97c28943b07ff99a.

📒 Files selected for processing (5)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/terminal/terminal-live-input.test.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/src/terminal/use-terminal-live-input-focus.test.ts
  • mobile/src/terminal/use-terminal-live-input-focus.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • mobile/src/terminal/use-terminal-live-input-focus.ts
  • mobile/src/terminal/terminal-live-input.test.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/terminal/use-terminal-live-input-focus.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Terminal live-input focus now accepts reopenFocusedInputWhenKeyboardHidden. The focus function refocuses an already-focused input after keyboard dismissal only when enabled. Android enables the setting, while other platforms retain the existing behavior. Tests cover both refocusing and preserving focus when the keyboard is hidden.

Merge Risk: ⚪ Minimal · up to 88070

This localized mobile change preserves iPad hardware-keyboard terminal focus while retaining the Android workaround; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the mobile iPad hardware-keyboard focus fix.
Description check ✅ Passed The description covers the problem, change, linked issue, testing, AI disclosure, and visual-proof exception, but omits some checklist sections.
Linked Issues check ✅ Passed The Android-only refocus change preserves iPad responder focus and addresses the external-keyboard terminal-input failure described in [#12706].
Out of Scope Changes check ✅ Passed All code and tests are limited to terminal live-input focus behavior and the linked iPad hardware-keyboard fix.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker
nwparker force-pushed the fix/ipad-hardware-keyboard-terminal-input branch from 8807014 to c6e7d70 Compare August 23, 2026 23:30
@nwparker

Copy link
Copy Markdown
Contributor

Readiness verdict: GO (P0: 0 · P1: 0 · P2: 1)

Scope reviewed: c6e7d702c66 — 5 files, mobile-only (mobile/app/h/[hostId]/session/[worktreeId].tsx, mobile/src/terminal/terminal-live-input{,.test}.ts, mobile/src/terminal/use-terminal-live-input-focus{,.test}.ts).

Checklist

# Area Result
01 SSH / remote / network N/A — no transport, RPC, or stream-frame surface touched. Client-local focus behavior only.
02 Crash / cast / retry / unbounded growth Pass — no casts, no !, no JSON.parse, no new collections or timers. The gate strictly narrows reachability of the existing blur() → 50 ms refocus() cycle (terminal-live-input.ts:243-249); that cycle still terminates in one hop because blur() makes the next isFocused() false.
03 Security / supply chain Pass — no deps, no lockfile, no shell/eval, no network sink, no secrets.
04 Performance & resources Pass (improvement) — on iOS every terminal tap previously cost a blur + a 50 ms timer + a second focus pass. It is now a single focus(). Strictly fewer native focus transitions and timers.
05 Functional correctness Pass — verified the only two consumers (use-terminal-live-input-focus.ts:71, [worktreeId].tsx:989); both updated. The option is required (not optional), so a missed call site would be a compile error — pnpm typecheck is clean. Both branches covered at the primitive and hook seams.
06 Backward compatibility & data loss Pass — no persisted state, schema, migration, setting, or serialized contract. No mobile-facing wire surface touched, so a new client against an old desktop (and the reverse) is unaffected.
07 Cross-platform & remoting Pass — behavior is selected by a runtime Platform.OS check, per AGENTS.md. Android path byte-for-byte unchanged; desktop/Windows/WSL/Linux untouched.

Why the Android-only gate does not regress iPhone

The narrowing is safe because the guarded branch is unreachable on iOS through the app's own dismissal paths. Keyboard.dismiss() resolves to dismissKeyboard() → TextInputState.blurTextInput(TextInputState.currentlyFocusedInput()) (RN 0.83.9, Libraries/Utilities/dismissKeyboard.js), i.e. it blurs on both platforms. So on iOS an app-initiated dismiss leaves isFocused() === false and the plain focus() path runs — the same call the old code made. The workaround is only needed on Android, where the IME can be hidden by the system Back button without RN blurring the TextInput. The terminal surface also sets no keyboardDismissMode, so iOS interactive drag-dismiss (the one iOS case that keeps focus while the keyboard hides) is not in play here.

Gates run locally (this worktree, at c6e7d702c66)

Gate Result
pnpm vitest run src/terminal/terminal-live-input.test.ts src/terminal/use-terminal-live-input-focus.test.ts 2 files / 49 tests passed
pnpm typecheck (tsc --noEmit) clean
pnpm lint (oxlint) clean
pnpm format:check (oxfmt, 1235 files) clean

Simulator validation — and its proven limit

Ran the flow end-to-end on a booted iPad Pro 13-inch (M5) simulator (Xcode 26.1.1) against the repo's own mobile/scripts/mock-server.ts, with Simulator I/O → Keyboard → Connect Hardware Keyboard enabled to hold keyboardHeight at 0 — the iPad-with-Magic-Keyboard condition.

At this head, hardware-keyboard input works. Tapping the terminal brings up no software keyboard, and all 18 synthesized hardware keystrokes reach the host — the mock server logged the exact bytes ([SEND] terminal=term-1 text="a" + text="aaaaaaaaaaaaaaaaa" = 18 characters; the glyph is a synthetic-CGEvent artifact of driving the Simulator, the count is the signal).

Tap with hardware keyboard connected — no software keyboard, keyboardHeight === 0:

proof-1-no-software-keyboard.png

After typing on the hardware keyboard — the hidden responder captured all 18 keystrokes:

proof-2-hardware-keystrokes-captured.png

Limit (important, and the reason this is a supplement rather than the primary evidence): I also ran the negative control — temporarily forcing reopenFocusedInputWhenKeyboardHidden: true (the pre-fix behavior), confirming Metro re-bundled the changed module, and repeating the identical tap-and-type. It delivered the same 18 characters. So the iOS Simulator's synthetic hardware-keyboard mode cannot discriminate this fix: the guarded branch needs the hidden TextInput to already hold first responder while keyboardHeight === 0, and the Simulator does not keep a hardware-keyboard responder attached to the RN TextInput across taps the way a physically-attached Magic Keyboard does. The temporary edit has been reverted; the tree is clean at c6e7d702c66.

The load-bearing evidence for the fix therefore remains the author's physical iPad Pro M5 + Apple Magic Keyboard run recorded in the PR description, plus the unit coverage at both seams. The simulator run is a genuine non-regression check, not a repro of the original failure.

P2 (non-blocking)

  • use-terminal-live-input-focus.ts:32-40 — the destructured parameter list places reopenFocusedInputWhenKeyboardHidden before liveInputEnabled, breaking the otherwise alphabetical ordering used throughout this file. Cosmetic; lint is clean.

Residual risk (not a finding)

Automated coverage for the iPad hardware-keyboard path is inherently manual — no simulator or CI lane can reproduce the responder state that triggers the bug (demonstrated above). A regression here would only be caught by a human on real hardware.


Summary

This is a 3-line behavior change in mobile terminal focus handling, and it is ready to merge. It stops iOS from applying an Android-specific workaround: previously any terminal tap with the software keyboard absent would blur the hidden text field and schedule a re-focus, which on an iPad with an attached hardware keyboard meant keyboardHeight was permanently 0, so every tap tore down the input responder and physical keystrokes went nowhere. The workaround is now gated to Android, where it is actually needed.

Nothing release-blocking surfaced. The one thing worth knowing before you merge is a verification caveat rather than a defect: I built a full iPad simulator harness and confirmed hardware-keyboard typing works at this head, but the A/B negative control proved the simulator behaves identically with and without the fix, so it cannot stand in for the real-hardware evidence. The physical-iPad run in the PR description remains the actual proof, and the unit tests pin both branches so the gate cannot be silently flipped back.

Action required before release: none. The single P2 is a parameter-ordering nit and can be ignored or folded into any later touch of the file.

@nwparker

Copy link
Copy Markdown
Contributor

CI settled after the readiness review above: 47/47 required checks pass, e2e skipped (no changed e2e specs — mobile-only diff), and GitHub now reports MERGEABLE / CLEAN at c6e7d702c66. The earlier UNSTABLE was a second verify job sitting queued for a runner, not a failure. No push was needed — local HEAD already matched the PR head exactly.

@nwparker

nwparker commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Updated against main after the session-screen extraction. The sole call-site change now lives in use-mobile-session-terminal-runtime.ts; iOS preserves its responder and Android retains the existing blur/refocus workaround. No native capture, Chat/navigation, or transport work from #18901 is included. Final diff: 6 files, +70/-11. The extra file updates only the parity string count/hash for the added android platform literal. Local validation: 509 mobile test files passed, 4,163 tests passed / 3 skipped; mobile typecheck passed. Original focused regressions retained and passing. Fresh fork workflows approved and running. Original author-reported physical iPad/Magic Keyboard proof remains historical; no new physical typing run is claimed.

@nwparker
nwparker merged commit b51bbf3 into stablyai:main Sep 6, 2026
20 checks passed
Jinwoo-H added a commit that referenced this pull request Sep 6, 2026
Resolves eight conflicts from main's SSH e2e lane restructure and the mobile
relay stream-cancellation fix.

- e2e.yml / run-ssh-docker-e2e.mjs / pr-e2e-gate-contract.test.mjs: keep main's
  lane structure and re-express only the hosted-mobile-webview SSH exclusion.
- reliability-gates.jsonc: main's file plus the branch's mobile-hybrid gate.
- mobile-relay-rpc-streams.ts: main's cancellation machinery replaces the
  branch's equivalent, generalized to every server-assigned-id method.
- docker-ssh-relay-connection.ts: main's delegation to connectSshTestTarget,
  with the branch's connect timeout moved into that shared helper.
- mobile-session-route-parity.test.ts: digest re-frozen for main's #12772.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(mobile): preserve iPad terminal input focus

* Keep incoming main test formatting unchanged

---------

Co-authored-by: Neil <[email protected]>
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.

[Bug] Cannot use external (e.g. magic) keyboard on ipad on terminal windows

5 participants