Repository navigation
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Android key capture module — a new Android-only local Expo module (
orca-terminal-key-capture) wraps the hidden live-input field on the focus path sodispatchKeyEventsees IME and hardware keys beforeTextView. It takes chords (and swallows their key-up) decisions via the pureTerminalKeyChord.from, falling back to plain children when the module is absent. - JS chord→bytes bridge —
createTerminalKeyChordInputreusesbuildTerminalShortcutKeyand the accessory-bar send path (handleAccessoryKey), so no new byte table or transport path is introduced. - Cross-platform shortcut table —
CTRL_PRINTABLE_BYTESgains xterm's Ctrl+2…Ctrl+8 and Ctrl+/ codes, which also lets the custom-key dialog build those chords on iOS/web. - Dock wiring and tests — the live
TextInputnow sits insideTerminalKeyCapture; route-parity pins moved (leaf 61→62, style refs 172→173) and new unit tests pin the chord bytes.
I checked the load-bearing claims against AOSP sources: META_CTRL_MASK | META_ALT_MASK | META_META_MASK do include the *_ON bits, so readChord's getUnicodeChar(metaState and chordModifiers.inv()) does strip ctrl/alt/meta while keeping shift; and TextView.onKeyShortcut handles META_CTRL_ON | META_SHIFT_ON + V as paste-as-plain-text, so leaving Ctrl+Shift+V to the field still pastes on Android (the UI Paste button remains the primary path). The two choices the author flagged — Ctrl+V → \x16 and Ctrl+Space → NUL — are both consistent with terminal semantics and the accessory bar, so I have no objection to either; the Ctrl+Space cost (hardware layout switch) is worth a maintainer call only if that gesture matters to this audience. The author's documented gaps (hardware/Bluetooth device path, Alt+Enter key-up, non-Latin hardware layouts, and the local-only Gradle tests) are accurate and understood.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an Android native view that captures selected physical keyboard chords and emits their key and modifier data. Adds conversion from captured chords to terminal accessory inputs, including additional Ctrl byte mappings. Wraps the live-input field with platform-specific key capture and dispatches converted inputs through the existing accessory-key handler. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Android keyboard chords should generally reach the terminal as intended. Two edge cases remain. If two input devices send the same key at once, a stray key-up can reach the text field. The native key-event path also has no automated test coverage. Both are bounded, so this is mergeable, but the owner should be aware of them. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Keyboard chords gain a new route to the active terminal, but the route uses the existing command controls. No security bypass was established. Hardware-keyboard and interrupted-key behavior remain uncertain. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The PR still adds shared
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/OrcaTerminalKeyCaptureView.kt (1)
40-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftAdd an event-path test for
OrcaTerminalKeyCaptureView.
TerminalKeyChordTest.kttests onlyTerminalKeyChord.from()with hand-built character values. It does not construct aKeyEventor exercisedispatchKeyEvent, so the Ctrl/Alt/Meta masking, AltGr detection, and combining-accent extraction remain untested.Add a focused Robolectric or instrumented test that sends Ctrl+C and modifier combinations through
dispatchKeyEventand asserts the resulting chord payload. Add the required test setup, since this module currently declares only JUnit.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: db606396-b33c-405f-9769-1ddb4b25fc25
📥 Commits
Reviewing files that changed from the base of the PR and between 27b823f and ea7df33d441d2806f0513138fb65964038c2867a.
📒 Files selected for processing (19)
mobile/modules/orca-terminal-key-capture/android/.gitignoremobile/modules/orca-terminal-key-capture/android/build.gradlemobile/modules/orca-terminal-key-capture/android/src/main/AndroidManifest.xmlmobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/OrcaTerminalKeyCaptureModule.ktmobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/OrcaTerminalKeyCaptureView.ktmobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/TerminalKeyChord.ktmobile/modules/orca-terminal-key-capture/android/src/test/java/expo/modules/orcaterminalkeycapture/TerminalKeyChordTest.ktmobile/modules/orca-terminal-key-capture/expo-module.config.jsonmobile/modules/orca-terminal-key-capture/package.jsonmobile/modules/orca-terminal-key-capture/src/index.tsmobile/src/session/MobileSessionCommandDock.tsxmobile/src/session/mobile-session-command-input-styles.tsmobile/src/session/mobile-session-route-parity.test.tsmobile/src/terminal/TerminalKeyCapture.android.tsxmobile/src/terminal/TerminalKeyCapture.tsxmobile/src/terminal/terminal-accessory-keys.test.tsmobile/src/terminal/terminal-accessory-keys.tsmobile/src/terminal/terminal-key-chord-input.test.tsmobile/src/terminal/terminal-key-chord-input.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
|
About the CodeRabbit nitpick asking for an event-path test of |
23e1bb8 to
d524b83
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Rebased the branch onto the newer
main(21f8e0f9) and re-recorded themobile-session-route-parity.test.tspins against it: hook/callback/effect/host-JSX/leaf/style/capability hashes moved, while the counts stay at the PR's intended values (hooks 281, callbacks 80, leaf 62, style refs 174). - No functional PR content changed since the previous review; the dock's
hostOs/useKeyboardPersistingTapslines present in a raw branch-vs-prior-sha diff come frommain, not this PR.
I re-ran the changed tests on head: mobile-session-route-parity.test.ts, terminal-key-chord-input.test.ts and terminal-accessory-keys.test.ts all pass (18 tests). The pin moves are consistent with the tree, so the parity guard is not masking a regression.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Match repeated key-downs to the consumed key event. · OrcaTerminalKeyCaptureView.kt:25-38
mobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/OrcaTerminalKeyCaptureView.kt:25-38
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMatch repeated key-downs to the consumed key event.
If the user presses Ctrl+C, releases Ctrl while holding C, and waits for key repeat, Android can send a repeat
ACTION_DOWNfor C without Ctrl.readChordreturns null, so the nestedTextInputreceives that key-down. The following CACTION_UPstill removesKEYCODE_CfromtakenKeyCodesand is swallowed. The editable field can therefore receive a bare repeated character without its matching key-up.Track the consumed event identity and consume repeats for that event.
Suggested fix
- private val takenKeyCodes = mutableSetOf<Int>() + private data class TakenKeyDown( + val keyCode: Int, + val deviceId: Int, + val scanCode: Int, + val downTime: Long + ) + + private val takenKeyDowns = mutableSetOf<TakenKeyDown>() + + private fun keyDownIdentity(event: KeyEvent) = TakenKeyDown( + keyCode = event.keyCode, + deviceId = event.deviceId, + scanCode = event.scanCode, + downTime = event.downTime + ) override fun dispatchKeyEvent(event: KeyEvent): Boolean { when (event.action) { KeyEvent.ACTION_DOWN -> { + val identity = keyDownIdentity(event) + if (event.repeatCount > 0 && identity in takenKeyDowns) return true val chord = readChord(event) if (chord != null) { - takenKeyCodes.add(event.keyCode) + takenKeyDowns.add(identity) onTerminalKey(chord.toPayload()) return true } } - KeyEvent.ACTION_UP -> if (takenKeyCodes.remove(event.keyCode)) return true + KeyEvent.ACTION_UP -> if (takenKeyDowns.remove(keyDownIdentity(event))) return true } return super.dispatchKeyEvent(event) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 51284656-67d9-4b63-993f-75b3fd5bc894
📥 Commits
Reviewing files that changed from the base of the PR and between 23e1bb86d813690b131430febb8732f7c20cb1a1 and d524b8397c07207e7e0b481058eb673c4f31bbe4.
📒 Files selected for processing (2)
mobile/src/session/MobileSessionCommandDock.tsxmobile/src/session/mobile-session-route-parity.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.
|
Repeat key-down matching (accepted, narrower fix in Real edge: Ctrl+C, release Ctrl while still holding C → Android emits repeat I did not take the suggested Instead the repeat guard runs only after |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Consume repeats of a captured chord's key —
OrcaTerminalKeyCaptureView.dispatchKeyEventnow swallows anACTION_DOWNrepeat whose key code was already taken as a chord when the chord no longer matches (the modifier was released while the key is still held), so the hidden live field no longer receives an orphan key-down whose key-up the view consumes onACTION_UP. The chord still re-matches and resends while its modifier is held.
I checked the new guard against AOSP key-repeat behavior: repeats reuse the captured metaState (InputDispatcher::synthesizeKeyRepeatLocked), so chord repeats re-enter readChord and resend as before, and the KeyEvent contract does permit repeatCount > 0 downs. The residual edge — a keyCode-only match can over-swallow after a lost ACTION_UP or with two same-key devices — is rare, low-impact, and identical in spirit to the identity-matching suggestion already raised from another reviewer, so I'm not re-raising it. No Pullfrog review threads were open to retire.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Android IMEs such as Unexpected Keyboard, and hardware keyboards, send Ctrl chords, Esc, Tab, arrows and F-keys as KeyEvents rather than text. The live terminal input is a hidden React Native TextInput, and React Native's Android input connection forwards only Backspace, Enter and digits to onKeyPress, so TextView dropped the rest or ran them as copy/paste/select-all shortcuts and nothing reached the PTY. A local Android-only Expo view now wraps the live-input field. It sits above ReactEditText on the focus path, so dispatchKeyEvent sees each key-down before TextView and before shortcut handling. The pure TerminalKeyChord decision picks which keys to take; the JS side maps the chord through the existing buildTerminalShortcutKey and sends it through handleAccessoryKey, the same path the accessory bar uses. xterm's Ctrl+/ and digit-row control codes (Ctrl+2 to Ctrl+8) are added to the shared shortcut table. That table also feeds the custom-key builder on every platform, so these chords, which used to build to nothing, can now be saved as custom keys on iOS and the web page as well. The key-capture wrapper itself is Android-only and wraps only the live-input field, so iOS, the web page and buffered input mode keep the plain field. Constraint: React Native Android ships as a prebuilt AAR, so patching ReactEditText sources does not reach the build Constraint: Unexpected Keyboard sends chords via InputConnection.sendKeyEvent(KEYCODE_x, META_CTRL_ON) with the VIRTUAL_KEYBOARD device id Rejected: ReactActivityHandler.onKeyDown hook | only keys the view tree left unhandled reach it, so arrows never arrive while the field holds text Rejected: taking KEYCODE_DEL | the field already turns every Backspace into PTY erases, so Ctrl+Backspace would erase twice Directive: consume the key-up of every taken key-down; ReactEditText hides the keyboard on Enter's key-up Directive: keep buffered input mode unwrapped and leave Ctrl+Shift+V to the field's paste Directive: right Alt is AltGr when the layout maps a character to it; only left Alt is an Esc prefix Tested: headless API 33 emulator with Unexpected Keyboard 2.1.0 against the mock server: Ctrl+C, Esc, Tab and Up arrive as \u0003, \u001b, \t, \u001b[A; a plain letter and Backspace (\u007f, once) are unchanged Tested: ./gradlew :orca-terminal-key-capture:testDebugUnitTest (local only; no PR workflow runs it), mobile tsc --noEmit, check:tests-typecheck, full mobile vitest (892 files), mobile lint and format:check, root check:code-quality:changed Not-tested: physical Bluetooth keyboards and non-Latin hardware layouts on a real device
Ctrl+C를 누른 뒤 Ctrl만 떼고 C를 계속 누르면 Android가 modifier 없는 repeat ACTION_DOWN을 보낸다. readChord가 null을 반환해 그 repeat이 TextInput으로 새고, 이어지는 ACTION_UP은 takenKeyCodes에 의해 소비되어 필드가 key-up 없는 key-down을 받는다. repeatCount>0이고 keyCode가 이미 소비된 키면 조용히 삼킨다. modifier를 유지한 chord 리피트는 readChord가 먼저 처리하므로 계속 재전송된다.
7b62fe8 to
5b9e42a
Compare
|
코드의 key-down을 가로챈 뒤 key-up 전에 필드가 포커스를 잃으면 기록이 남아, 포커스 복귀 후 수식어 없이 같은 키를 길게 누르면 첫 입력 이후의 반복이 조용히 삼켜졌다. 포커스 상실과 뷰 분리 시 기록을 지운다. 소비 결정 상태 기계를 TerminalKeyDispatchTracker로 분리해 디스패치 판정 (코드 획득, 반복 삼킴, key-up 소비, 포커스 해제)를 JVM 테스트가 직접 검증하게 했다.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a0e6a7f2-dc7b-46eb-b365-9685b8cd20b1
📒 Files selected for processing (3)
mobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/OrcaTerminalKeyCaptureView.ktmobile/modules/orca-terminal-key-capture/android/src/main/java/expo/modules/orcaterminalkeycapture/TerminalKeyDispatchTracker.ktmobile/modules/orca-terminal-key-capture/android/src/test/java/expo/modules/orcaterminalkeycapture/TerminalKeyDispatchTrackerTest.kt
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one coverage detail on the new focus-loss hook is noted inline.
Reviewed changes
Since the prior pullfrog review (7b62fe83), the branch was rebased onto main 31012ae and gained one commit (340bbfaa):
- Extracted the consume state machine —
OrcaTerminalKeyCaptureView's inlinetakenKeyCodesset becameTerminalKeyDispatchTracker, a pure class with a new JVM test (TerminalKeyDispatchTrackerTest) covering chord capture, repeat swallowing, key-up consumption, and focus-loss clearing. - Clear taken keys on focus loss —
clearChildFocusandonDetachedFromWindownow drop the record, so a stale key code can no longer swallow a later plain key's repeats after focus returns. - Dropped the route-parity test —
mobile/src/session/mobile-session-route-parity.test.tsleft the PR because upstream#23815deleted it onmain.
I read the new commit against the full PR diff. The extraction is behavior-preserving, the new test genuinely exercises the added clearing, and the focus-loss clearing is a net improvement over the previous unconditional record retention. I checked the trigger against AOSP (View.java:8143-8204, ViewGroup.java:851-873); one path it does not cover is detailed inline.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
키를 가로챈 뒤 포커스 상실로 기록을 지우면, 포커스가 복귀한 뒤 도착하는 key-up이 필드로 새서 Enter key-up이 키보드를 숨길 수 있었다. 기록을 포커스 변화와 무관하게 유지해 돌아온 key-up과 리피트를 계속 소비한다. 대신 같은 디바이스의 다음 fresh down이 이전 프레스의 기록을 폐기해, key-up이 다른 뷰로 배달된 프레스의 기록도 새 눌림을 가리지 않는다. 기록을 (keyCode, deviceId) 단위로 바꿔 하드웨어 키보드와 IME가 같은 키를 동시에 눌러도 각각의 key-up을 소비한다.
There was a problem hiding this comment.
Important
The new per-device key-up tracking in TerminalKeyDispatchTracker swallows a key-up from a device that never took a press, as long as some other device holds the same key code. The fix is one membership check.
Reviewed changes
Since the prior pullfrog review (340bbfaa), one commit (e35b382a) reworked how the capture view keeps and retires taken presses:
- Retired records on the next fresh down — the
clearChildFocusoverride andonFocusLoss()are gone; a taken press now survives focus loss and is retired byonKeyDownon that device's next non-repeat down, so every focus-loss path is covered rather than only Android'spropagate = trueroute. - Keyed pending presses by
(keyCode, deviceId)— two devices holding the same key code each get their own key-up swallowed, and repeat suppression checks the device too. - Reset on detach —
onDetachedFromWindowclears the map through the newonReset(). - Expanded the JVM tracker test — six cases now cover a returning key-up after focus, fresh-down retirement of a stale record, and per-device key-ups.
I read the new Kotlin against the full PR diff and traced the dispatch flow. The focus-loss rework is sound: a fresh down always retires the device's previous record before readChord, so a stale record cannot shadow a new plain press. The gap is in onKeyUp's return, detailed inline.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
onKeyUp이 pendingUps에 같은 keyCode가 있으면 deviceId 기록 없이도 true를 반환해, 필드가 실제로 받은 down의 key-up(예: IME가 보낸 plain Enter)까지 삼켜 필드가 끝나지 않는 down을 붙드는 문제를 수정했다. 이제 자기 디바이스의 기록을 소비한 경우에만 삼키고, 기록 없는 디바이스의 key-up은 필드에 전달된다. Tested: :orca-terminal-key-capture:testDebugUnitTest
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior pullfrog review (e35b382a), one commit (f15e6fe7) closes the per-device key-up gap that review flagged:
- Fixed
onKeyUpover-swallow —TerminalKeyDispatchTracker.onKeyUpnow returns whetherdevices.remove(deviceId)actually removed that device's record (val consumed = devices.remove(deviceId); return consumed) instead of returningtruewhenever the key code had any pending device. An up from a device whose down was never taken now falls through to the field. - Added a regression test —
TerminalKeyDispatchTrackerTest.aKeyUpFromADeviceWhoseDownWasNotTakenPassestakes Enter on the hardware device, asserts the IME's up passes, and asserts the hardware up is still consumed.
I traced the dispatch flow against the fix: onKeyDown retires the same device's prior record on every fresh down before readChord, and onChordTaken re-adds only a taken device, so the only behavior change is that a non-member device's up is no longer swallowed — exactly the reported bug. The new test exercises the fixed branch (it would fail against the previous return true). No other files changed in this delta, and no new findings.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Hi @Jinwoo-H, gentle nudge on this one when you have a moment. It now fixes its own issue, #25496 (item C of #9702, which stays open), and I've posted a prebuilt APK in #9702 so someone with a Bluetooth keyboard can check the hardware path. My other open mobile PRs are small and linked to issues too, in case they fit the same pass: #19599 (terminal follows the phone's light/dark setting), #23419 (optional keyboard resize), #25502 (recover a missed web-ready) and #25503 (slice large terminal writes). |
|
Merged the Android terminal keyboard fix in #31666, adapted to the current OTA input architecture and existing ordered send queue. Thank you, @kargnas, for the original keyboard capture work. Sangrak Choi is credited as a co-author on the merged commit. Closing this source PR as superseded. The merged implementation covers the Android control-key behavior and shared shortcut mappings; physical Bluetooth keyboard coverage remains an explicit validation gap. |

ELI5
On Android, the keys a terminal needs most (Ctrl+C, Esc, Tab, arrows) never reached the terminal on the computer when they were typed on a keyboard app like Unexpected Keyboard or on a Bluetooth keyboard. Only the on-screen accessory buttons worked. Now keys from a keyboard app go through to the terminal the same way the accessory buttons do. Bluetooth keyboards take the same code path, but that path has not been tested on a device yet.
What Changed
Before (Android, live input mode): Ctrl chords, Esc, Tab, arrows, Home/End, PageUp/PageDown and F-keys from a keyboard app or a hardware keyboard never reached the terminal (the hidden field dropped them, or used Tab and arrows for its own focus and cursor). Ctrl+C/A/X/Z/V could instead run as copy / select-all / cut / undo / paste on the hidden text field.
After: those keys reach the terminal as the bytes a terminal expects:
\x03, Esc sends\x1b, Up sends\x1b[A.\x1b[Z, Alt+b sends\x1bb, Ctrl+Up sends\x1b[1;5A.\x16(quoted-insert, as in any terminal) instead of pasting. Paste stays on Ctrl+Shift+V and the Paste button.\x00).Plain typing, Enter and Backspace work exactly as before.
Also on iOS and the web page: the shared shortcut table gained xterm's control codes for Ctrl+2 to Ctrl+8 and Ctrl+/. That table also builds custom keys in the "add custom key" dialog on every platform. Before, those chords built to nothing and Save did nothing; now they can be saved as custom keys. This is the only change outside Android.
Mechanism:
TextInput. On Android, React Native's input connection forwards only Backspace, Enter and digits toonKeyPress. Every other key event went toTextView, which either dropped it or ran a text-editing shortcut.mobile/modules/orca-terminal-key-capture, adds an Android-only view that wraps only the live-input field. It is the field's parent on the focus path, so itsdispatchKeyEventsees each key beforeTextViewand before shortcut handling. This works the same for keys a keyboard app sends through its input connection and for hardware keys.TerminalKeyChord.ktis a pure function that decides which keys the view takes. It has a JVM unit test.ReactEditTexthides the soft keyboard on Enter's key-up (so Alt+Enter would close it), and a hardware Escape key-up would fall through to Back.terminal-key-chord-input.tsconverts the key to bytes with the existingbuildTerminalShortcutKeyand sends them throughhandleAccessoryKey, the same path the accessory bar uses. There is no new byte table and no new send path.TerminalKeyCapture.tsxrenders its children unchanged on iOS and the web page. On Android it falls back to plain children when the native view is missing, for example on a dev client built before this module.mobile-session-route-parity.test.tsused to pin that, and upstream removed the whole parity test in test: remove junk tests that assert source text instead of behavior #23815 along with the other source-text assertions.Keys the capture deliberately leaves to the field:
KEYCODE_DEL), including Ctrl+Backspace (Unexpected Keyboard's delete-word key). The field already turns every Backspace into a terminal erase, so taking it here would erase twice.On Cyrillic or Greek layouts, Ctrl+C still sends
\x03, because the letter is read from the key code.Why
Alternatives considered:
ReactEditTextor its input-connection wrapper: React Native Android ships as a prebuilt AAR, so a source patch does not reach the build.ReactActivity.onKeyDown: only keys the view tree left unhandled get there.TextViewhandles arrows itself while the field holds text, so arrows would never arrive.InputConnection.sendKeyEvent(KEYCODE_x, META_CTRL_ON)from the virtual keyboard device withFLAG_SOFT_KEYBOARDset.A wrapper view is the smallest place that sees both keyboard-app and hardware key events before
TextView, and it reuses the existing byte encoding and send path.Two choices a reviewer may want to weigh in on:
\x16. Live input behaves like a terminal, and Ctrl+Shift+V plus the Paste button still paste.Linked Issue
Fixes #25496
That issue is item C of #9702, "CTRL+C doesn't work on the keyboard, only on the UI button" (Android + Bluetooth keyboard), filed on its own. This PR leaves #9702 open: items A, B and D, and the iOS/iPadOS side, are out of scope.
Draft #18901 overlaps on the physical-keyboard half. Its capture view rejects keyboard-app events (
isPhysicalKeyboardEventexcludesFLAG_SOFT_KEYBOARDandVIRTUAL_KEYBOARD), so it does not cover the Unexpected Keyboard path. This PR stands on its own and is much narrower: key capture on Android only, and only for the live-input field.Visual Proof
No recording or screenshot is attached; attachments could not be uploaded from the environment this PR was prepared in.
What a reviewer would see on an Android phone with Unexpected Keyboard, in live input mode:
I verified this at the byte level against a mock server, not against a real shell; see Testing.
Testing
Prebuilt APK for trying this on a phone: https://github.com/kargnas/orca/releases/tag/preview-mobile-20261005-f1d7719. It contains this PR and my other open mobile PRs on top of
main40f9e7a3fc, and installs next to the regular app as "Orca Preview". On an Android 13 emulator it launched, paired withmobile/scripts/mock-server.tsand painted the terminal, and Ctrl+C and Up sent withadb shell inputin live input reached the mock host as\x03and\x1b[A.End to end (keyboard-app path): a headless Android emulator (API 33) with Unexpected Keyboard 2.1.0 as the active keyboard, paired with
mobile/scripts/mock-server.ts, with a terminal open in live input mode. The mock server logged:The soft keyboard stayed open throughout. I did not record a run without this change; the "before" above comes from the issue report and React Native's source.
Physical device, on ea7df33d (the same code as d524b8397c, rebased onto
main21f8e0f: the dock conflict wasmainswitching the keyboard type tohostOs(), and the route-parity pins were re-measured): a release APK (arm64) installed on a Galaxy Z Fold7 (SM-F966N, Android 16) next to the existing Orca app under a separate application id, paired with the same mock server overadb reverse, cover screen, live input mode:"\^[", Ctrl+4 sent"\^\", Ctrl+8 sent"\u007f". Ctrl with a Hangul letter does not produce a chord: the keyboard composes the letter instead, which is the keyboard's behavior, so Ctrl+C through the keyboard app is covered only by the emulator run above.adb shell input(the path a hardware keyboard takes, though from Android's virtual keyboard device rather than a Bluetooth one): Ctrl+C"\^C", Ctrl+D"\^D", Esc"\^[", Up"\^[[A", Alt+B"\^[b". After Esc the soft keyboard was still shown and the app stayed in front.Automated, on the final commit:
main21f8e0f: mobiletsc --noEmit,check:tests-typecheck,pnpm test(9755 passed, 6 skipped), the session-terminal closure test, andcheck:code-quality:changedpass.7b62fe83f9, consumes modifier-less key repeats of a taken chord):./gradlew --no-daemon :orca-terminal-key-capture:compileDebugKotlinpasses.main31012ae (featuree2078ac1b9, repeat fix5b9e42aca9): upstream's test: remove junk tests that assert source text instead of behavior #23815 cleanup deletedmobile-session-route-parity.test.ts, which was the only conflict. Mobiletsc --noEmit,check:tests-typecheck,pnpm test(9650 passed, 6 skipped), andcheck:code-quality:changedpass.340bbfaa4e): the taken-key record moved intoTerminalKeyDispatchTracker, whichclearChildFocusandonDetachedFromWindowclear, closing the stale-key repeat leak; the same class is covered by the newTerminalKeyDispatchTrackerTestJVM suite, which pins each dispatch decision (chord taken, repeat swallowed, matching key-up consumed, focus-loss clear)../gradlew --no-daemon :orca-terminal-key-capture:compileDebugKotlinandtestDebugUnitTestpass.e35b382a30): records no longer die on focus loss at all — pending presses are keyed by (keyCode, deviceId) and survive focus changes, so a key-up returning after refocus is still consumed, and two devices holding the same key each get their own key-up swallowed. A device's next fresh down retires its previous record, which keeps the earlier over-swallow fix intact on every focus-loss path (clearFocus,requestChildFocus, detach).TerminalKeyDispatchTrackerTestgrew to six cases covering both ends../gradlew --no-daemon :orca-terminal-key-capture:compileDebugKotlinandtestDebugUnitTestpass.f15e6fe75d):onKeyUpno longer swallows a key-up just because the key code has a pending record — the up is consumed only when the record for that device was actually removed, so an up whose down the field received (e.g. an IME plain Enter while a hardware Ctrl+Enter is still held) reaches the field instead of leaving it holding a down that never ends.TerminalKeyDispatchTrackerTestaddedaKeyUpFromADeviceWhoseDownWasNotTakenPasses../gradlew --no-daemon :orca-terminal-key-capture:compileDebugKotlinandtestDebugUnitTestpass.cd mobile && pnpm exec tsc --noEmitpasses.cd mobile && pnpm run check:tests-typecheckpasses.cd mobile && ORCA_BACKGROUND_LAUNCH=1 pnpm testpasses: 892 files, 9631 tests passed, 6 skipped. New and updated tests:terminal-key-chord-input.test.tscovers the chord-to-bytes conversion.terminal-accessory-keys.test.tspins every Ctrl+2 to Ctrl+8 control code; Ctrl+1 still builds nothing.cd mobile && pnpm lint && pnpm format:checkpass, and so dooxlint/oxfmt --checkon the changed files.pnpm run check:code-quality:changedat the repo root reports 0 new findings.Earlier on this branch (the code is identical; only the new digit-row test was added since):
cd mobile && npx expo prebuild --platform android --no-install, thencd android && ./gradlew --no-daemon :orca-terminal-key-capture:testDebugUnitTestpasses.TerminalKeyChordTestcovers which keys are taken and which are left to the field. This ran locally only: no PR workflow runs Gradle unit tests (the only Gradle step in CI isassembleReleasein the Android release workflow), and the same is true of the existingorca-mobile-web-shellKotlin tests../gradlew --no-daemon :app:assembleDebug, installed on the emulator for the end-to-end check above.node config/scripts/build-mobile-web-app-bundle.mjs,node config/scripts/verify-mobile-web-app-bundle.mjs, andconfig/scripts/build-mobile-web-app-bundle.test.mjs(47/47).config/scripts/mobile-web-app-session-terminal-closure.test.mjsalso passes.Not verified:
Unchanged pre-existing behavior: keyboard chords go through
handleAccessoryKey, so they share the accessory bar's existing ordering. If a batch of typed text is still in flight to the terminal, an accessory key or keyboard chord pressed right after it can arrive first. This PR does not change that.AI Disclosure
Developed with Claude Code (Claude Opus 5.5).
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
terminal.send. SSH and remote hosts receive the same bytes the accessory bar already sends. A dev client built without the new native module still loads this bundle and simply behaves as before.Checklist
N/Awith reason (no attachments; see Visual Proof for what a reviewer would see and the byte-level evidence)pnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred). This is a mobile-only change, so the mobile equivalents and the root changed-code gate were run locally; the desktop suites are left to CI.