Skip to content

fix(mobile): forward hardware keyboard controls to live terminals - #27257

Open
JonesZeng wants to merge 6 commits into
stablyai:mainfrom
JonesZeng:fix/ipad-hardware-keyboard-terminal
Open

JonesZeng wants to merge 6 commits into
stablyai:mainfrom
JonesZeng:fix/ipad-hardware-keyboard-terminal

Conversation

@JonesZeng

@JonesZeng JonesZeng commented Oct 10, 2026 •

Copy link
Copy Markdown

ELI5

An external keyboard should control the terminal, not just the hidden text field used for typing. This forwards navigation and control keys to the active terminal while leaving normal typing, Return, system shortcuts, and input-method composition with the native text input.

What Changed

  • Add a small native capture view around the existing live-input field (UIKit key commands on iOS; key dispatch on Android), with a normal TextInput fallback when the module is unavailable.
  • Translate terminal keys into the existing terminal-send path. Reuse its pending-text and send queues so arrows and repeated Backspace cannot overtake text or corrupt the field's editing baseline.
  • Keep Command/Meta shortcuts, Ctrl+Space, and Return on their existing paths. Do not capture keys while the focused field has marked/composing text; also reject queued JS events during composition, disconnects, and terminal switches.
  • Preserve the existing keyboard-focus lifecycle and protect a new hardware interaction from an older agent submission dismissing the keyboard.

Why

React Native's TextInput callbacks alone do not supply all external-keyboard navigation/control events. Capturing only these keys in a wrapper keeps the native text input responsible for printable text and IME behavior, instead of replacing the input system or creating a second terminal transport.

Linked Issue

Fixes #28197.
Related: #24943, #9000, and #9702. This does not add application-wide worktree/tab shortcuts or native-chat send shortcuts.

Visual Proof

The reporter confirmed that the original input fix works on their physical iPad. No before/after keyboard recording is attached yet; the visual-proof checklist remains open. Home-screen screenshots are not presented as proof of hardware-keyboard or IME behavior.

Testing

  • I manually tested these changes locally — the reporter confirmed the original fix on an iPad Air 5; the native composition guard added during review still needs a physical IME regression check.
  • Automated tests added/updated, or explained why not below

Validation after integrating upstream b3aa719a57:

  • 29 focused input, submission, pairing, and credential-retention test files: 398 tests passed.
  • Mobile TypeScript check passed; test-typecheck ratchet passed (966 test files, existing baseline unchanged).
  • Changed-code-quality gate passed; modified TypeScript formatting checks passed.
  • Xcode 26.5 iOS Release build and signature verification; previous revision also built and launched on an iPadOS 26.5 simulator and was installed on the reporter's iPad.

Native source-contract tests check wiring, not actual IME event delivery. Android native execution, full desktop builds, SSH end-to-end input, and a complete new-build physical keyboard/IME pass were not performed. Existing RPC formats are unchanged.

AI Disclosure

Implemented and reviewed with OpenAI Codex assistance. The reporter independently confirmed the original iPad fix. Test/build results and remaining verification limits are reported above.

Review

Reviewed key ownership, composition pass-through, repeated-key ordering, stale callbacks, and keyboard-dismissal races. Removed unused alternative focus hooks before submission.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Only mobile source/dependency changes are included. Personal signing, local bundle identifiers, provisioning, build artifacts, and pairing data are not committed. Key events reuse the existing host-owned input path for local and remote terminals.

Checklist

  • This PR is small and focused — one hardware-input path plus its native module and regression tests
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred) — scoped checks above passed; full repository matrix is left to CI

bbingz and others added 6 commits September 29, 2026 15:22
Update to upstream 5252884. Adapt hardware terminal input to the current composition, submission, and keyboard dismissal lifecycle; cover rapid erases, stale callbacks, and pending agent sends.
Use the typed native view manager and existing focus target contract. Reset the explicit keyboard latch before a modal renders, and keep unavoidable render-fixture assertions locally documented.
Update to b3aa719 and retain the verified native hardware-key input path. Drop unused alternative focus hooks so the upstream PR contains only the active input integration.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53df1278-0fe2-450f-977a-42ef8ae5c351
📥 Commits

Reviewing files that changed from the base of the PR and between 3a8f8e1 and cc4dc55.

⛔ Files ignored due to path filters (1)
  • mobile/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (28)
  • mobile/package.json
  • mobile/packages/expo-hardware-keyboard/android/build.gradle
  • mobile/packages/expo-hardware-keyboard/android/src/main/AndroidManifest.xml
  • mobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/ExpoHardwareKeyboardModule.kt
  • mobile/packages/expo-hardware-keyboard/android/src/main/java/expo/modules/hardwarekeyboard/HardwareKeyboardCaptureView.kt
  • mobile/packages/expo-hardware-keyboard/expo-module.config.json
  • mobile/packages/expo-hardware-keyboard/ios/ExpoHardwareKeyboard.podspec
  • mobile/packages/expo-hardware-keyboard/ios/ExpoHardwareKeyboardModule.swift
  • mobile/packages/expo-hardware-keyboard/ios/HardwareKeyboardCaptureView.swift
  • mobile/packages/expo-hardware-keyboard/package.json
  • mobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboard.types.ts
  • mobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboardModule.ts
  • mobile/packages/expo-hardware-keyboard/src/ExpoHardwareKeyboardModule.web.ts
  • mobile/packages/expo-hardware-keyboard/src/HardwareKeyboardCaptureView.tsx
  • mobile/packages/expo-hardware-keyboard/src/index.ts
  • mobile/packages/expo-hardware-keyboard/tsconfig.json
  • mobile/src/session/MobileSessionCommandDock.test.tsx
  • mobile/src/session/MobileSessionCommandDock.tsx
  • mobile/src/session/MobileTerminalLiveInputBar.tsx
  • mobile/src/session/terminal-live-submit-keyboard-dismissal.test.tsx
  • mobile/src/session/use-mobile-session-terminal-runtime.ts
  • mobile/src/terminal/terminal-live-hardware-key-mapping.test.ts
  • mobile/src/terminal/terminal-live-hardware-key-mapping.ts
  • mobile/src/terminal/terminal-live-hardware-key-native-contract.test.ts
  • mobile/src/terminal/terminal-live-input-commit.test-support.ts
  • mobile/src/terminal/use-terminal-live-input-commit.test.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-hardware.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Adds an Expo package for native Android and iOS hardware-key capture. The terminal input handler maps captured events to terminal bytes or local edits and accounts for pending text. The session UI now renders live input through a dedicated component and passes it the hardware-key handler. Tests cover native source contracts, key mapping, input handling, UI behavior, and keyboard dismissal.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to cc4dc

No confirmed issue remains that should block merging. Physical keyboard and IME validation is still outstanding.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 21 files. (7 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed #24943 requires hardware-keyboard input to reach the active terminal for Live Input, including interactive navigation such as vi. The PR adds iOS and Android capture views, maps navigation and contr…
Out of Scope Changes check Passed The changes stay within #24943. The native module, JavaScript fallback, terminal mapping, commit-path integration, lifecycle handling, and regression tests directly support hardware-key input for Live…
Title check Passed The title clearly and concisely describes the primary change: forwarding hardware keyboard controls to mobile live terminals.
Description check Passed The description is complete and directly covers the user impact, implementation, rationale, linked issue, testing, limitations, review notes, and checklist. It clearly discloses that visual proof, phy…
Full details: Docstring Coverage

Explanation

Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 21 files. (7 skipped: 7 unsupported.)

  • Fix all pre-merge checks with AI
  • 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.

@nwparker

Copy link
Copy Markdown
Contributor

The Android OTA control-key path merged in #31666. Thank you for the composition-guard work; zenghaolun02 is credited as a co-author on the merged commit.

Keeping this PR open because its iOS/native hardware-keyboard and focus-protection scope is not fully superseded by that Android-only capture path. Any follow-up should retain that remaining scope and avoid duplicating the merged Android OTA implementation.

This branch has not been deployed

No deployments
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]: Mobile hardware-keyboard navigation and control keys do not reach live terminals

3 participants