Skip to content

fix(mobile): handle Android terminal keyboard chords in OTA sessions - #31666

Merged
nwparker merged 2 commits into
mainfrom
nwparker/mobile-b4-android-keys
Oct 22, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/mobile-b4-android-keys

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​305 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​298
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129

What changed (ELI5)

Android keyboards can send Ctrl+C, Esc, Tab, and arrows, but the live input treated them like a normal text box. Ctrl+C disappeared and Tab moved focus away, so the next arrow never reached the terminal. Capture those controls on the Android live field, encode them with the existing shortcut builder, and send them through the existing accessory queue. Enter, deletion, ordinary typing, composition, AltGr, and platform shortcuts retain their existing handling.

The Android session runs the desktop OTA React Native Web bundle inside its native WebView. This extends that route's existing field binding. The capture gate is Android-only; iOS and standalone web keep their current keyboard behavior. It adds no native module or RPC method and reuses the pending-text acknowledgement queue and terminal/disconnect generations.

Before / after

Same API35 x86_64 headless Android emulator, Unexpected Keyboard2.1.0, paired v2 encrypted test host, and production-built OTA bundles. Tapped Ctrl then C; swiped Q→Esc, A→Tab, and the directional key upward. The host echoes only bytes received through terminal.send.

Before After
(screenshot removed: contained real product data) (screenshot removed: contained real product data)

Before: only Esc (1b) and Tab (09) arrive; Tab dismisses the keyboard and the arrow is lost. After: Ctrl+C (03), Esc (1b), Tab (09), and Up (1b 5b 41) arrive once each, and the live field stays focused. Both runs use Orca's existing DOM renderer fallback, enabled only at runtime because Swiftshader clips WebGL glyphs. No renderer source changes or synthetic CDP key events are used.

Verification

  • 110 focused tests pass across nine files. The real field→send-action→live-commit hooks cover delayed text acknowledgement, exactly-once control delivery, terminal switch away/back, disconnect/reconnect, and listener cleanup. Only the RPC boundary is mocked in those lifecycle tests.
  • Changed-code quality passes. Production OTA bundle builds. Android-only gating, duplicate suppression before RNWeb, Shift+Tab/modified arrows, composition/AltGr/Meta/Ctrl+Space passthrough, and current callbacks have focused coverage.
  • Native Android key injection verifies Ctrl+C/Esc/Tab/Up once, plus ordinary a, b, Backspace (7f) and Enter (0d). After native composition ends, Ctrl+C, Shift+Tab and Ctrl+Up arrive once as 03, 1b 5b 5a, 1b 5b 31 3b 35 41.
  • Fcitx5 Android0.1.3 Pinyin in “Composing pinyin” mode produces real DOM compositionstart, updates, isComposing=true and keyCode229. Native Ctrl+C while ni is composing sends no interrupt. Candidate selection commits 你.
  • Baseline and scoped fixed bundles send the same Pinyin wire sequence: n, i, 7f 7f, 你. Existing Android preedit mirroring forwards the preedit and replaces it with delete bytes; the visually blank host row is those two deletes, not an empty payload. This PR preserves that behavior and does not claim atomic CJK transport.
  • Local typecheck remains affected by the existing RNWebView dependency mismatch in TerminalWebView.tsx; no diagnostics remain in changed files. All applicable CI checks pass on published head 418acb40ef15, including canonical mobile verification, static analysis/typecheck, and OTA bundle validation.

Native CJK regression comparison (same IME/configuration; candidate tapped on the native keyboard). A fresh build of base 0b82f88e9f2b produced 4e067e1ad1ba; rebuilding published 418acb40ef15 reproduced the tested gated bundle 5aa3f46ae070 exactly:

Baseline commit Android-scoped fix
(screenshot removed: contained real product data) (screenshot removed: contained real product data)

Review and merge risk

Low after full-host Android verification. The Android-only binding, composition/default-prevented/AltGraph guards, send-queue lifecycle tests and previous native Unexpected Keyboard/Fcitx Pinyin baseline comparison remain covered.

The same published OTA 5aa3f46ae070 now runs against a full source-built Orca host with its production encrypted RPC, input floor, real terminal daemon and macOS Bash PTY; no fixture RPC adapter. Actual Android key events interrupted sleep 30 with Ctrl+C, recalled it with Up, and completed b5-completion-marker with Tab. A raw-mode process in that real PTY recorded F1=1b 4f 50, Left=1b 5b 44, Ctrl+A=01, Alt+Left=1b 5b 31 3b 33 44, Tab=09, Ctrl+D=04, once per input. Ordinary native text and Enter also reached Bash. This closes the fixture-host limitation in the prior proof.

Physical Bluetooth keyboards, additional IMEs and a broad TUI/shell matrix remain untested. The headless emulator's Swiftshader renderer clips terminal glyphs, so this pass uses production host terminal readback for exact output/byte assertions; no claim of resolving that unrelated rendering issue. Existing preedit forwarding is preserved. Current-head CI passes. No automatic merge requested.

Community credit

Continues the keyboard work from #23418 by Sangrak Choi, with composition guard inspiration from #27257 (zenghaolun02's composition fix). Both are credited as co-authors. The native-module approach was adapted to today's OTA architecture and existing send queue.

Fixes #25496

Earlier fixture-host screenshot: native Android → encrypted RPC → real Bash PTY (bundle 5aa3f46ae070; runtime DOM fallback for Swiftshader). The full production-host verification above uses actual PTY readback:

(screenshot removed: contained real product data)

Claim live-field keydown controls before RNWeb edits or moves focus, reuse
accessory ordering and stale-target guards, and leave IME/text input alone.

Fixes #25496

Co-authored-by: Sangrak Choi <[email protected]>
Co-authored-by: zenghaolun02 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 64546550-4ed1-452f-aa5c-befdb56b8953
📥 Commits

Reviewing files that changed from the base of the PR and between afcb385 and 418acb4.

📒 Files selected for processing: 11
  • mobile/src/session/terminal-field-submit-binding-send.test.tsx
  • mobile/src/session/use-mobile-session-terminal-send-actions.ts
  • mobile/src/terminal/terminal-accessory-keys.ts
  • mobile/src/terminal/terminal-key-chord-input.test.ts
  • mobile/src/terminal/terminal-key-chord-input.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/src/terminal/terminal-text-field-submit-binding.ts
  • mobile/src/terminal/terminal-text-field-submit-binding.web.test.ts
  • mobile/src/terminal/terminal-text-field-submit-binding.web.ts
  • mobile/src/terminal/use-terminal-text-field-submit-binding.test.tsx
  • mobile/src/terminal/use-terminal-text-field-submit-binding.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Exercise pending-text acknowledgement, terminal switch, disconnect and listener cleanup through the live hooks.
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]: Android: Ctrl chords, Esc, Tab and arrows from keyboard apps and hardware keyboards don't reach the terminal

1 participant