Skip to content

fix(mobile): preserve Japanese IME composition - #10162

Closed
bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/mobile-japanese-ime
Closed

bbingz wants to merge 2 commits into
stablyai:mainfrom
bbingz:fix/mobile-japanese-ime

Conversation

@bbingz

@bbingz bbingz commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a local Expo native input view that observes committed iOS and Android IME text without forwarding marked/composing text to the terminal.
  • Keep IME confirmation separate from terminal Enter, deduplicate Android key/editor-action Enter, and preserve empty-field Backspace reporting.
  • Preserve the existing Hangul composition mirror while protecting trailing Japanese kana long enough for flick modifiers such as small kana, dakuten, and handakuten.

Addresses #7427.

Screenshots

No visual change.

Testing

  • cd mobile && ./node_modules/.bin/vitest run — 317 files passed; 2,315 tests passed and 2 skipped
  • cd mobile && ./node_modules/.bin/tsc --noEmit
  • cd mobile && ./node_modules/.bin/tsc --noEmit -p packages/expo-terminal-live-input/tsconfig.json
  • cd mobile && ./node_modules/.bin/oxlint
  • cd mobile && ./node_modules/.bin/oxfmt --check .
  • Expo prebuild and all-platform Metro export
  • Android :app:assembleDebug
  • iOS simulator build for the ExpoTerminalLiveInput scheme
  • Added regression coverage for Japanese snapshot replacement, small kana, dakuten/handakuten, decomposed modifiers, late-modifier convergence, Android Enter deduplication, IME_ACTION_NONE, focus state, empty Backspace, and route wiring
  • Full iOS app-scheme build — blocked under Xcode 27 by the existing Expo Router LinkPreviewNativeActionView.swift use of the iOS 16-only subtitle API while the app target is iOS 15.1

AI Review Report

Grok ran three adversarial review rounds. It initially flagged possible Android double Enter delivery, leaking Japanese modifier bases, stale focus state, and incomplete editor-action/fallback coverage. Those paths were changed or covered with tests; its final review reported no actionable findings.

Claude independently reviewed the complete change and then reran an exact-head gate on 8a23618310..f94b83b34a. It verified the diff, focused tests, type checking, lint/format checks, and the absence of overlap with the latest upstream terminal-routing change; both reports ended with no actionable findings.

Cross-platform review confirmed that this PR is limited to the mobile iOS/Android input bridge plus its web/test fallback. It does not change Electron desktop shortcuts or labels, filesystem paths, shell commands, or platform-specific desktop behavior. The existing shared PTY send path, including SSH sessions, remains unchanged.

Security Audit

  • No third-party dependency was added; the Expo module is local to the mobile workspace.
  • The change adds no command execution, path handling, auth, secret, external IPC, or native network surface.
  • Terminal input still flows through the existing terminal.send path and its 256 KiB payload guard.
  • Native event payloads are limited to committed text, Enter, Backspace, and focus state.

Notes

  • Physical-device validation with a Japanese iOS/Android keyboard was not available, so this PR uses Addresses #7427 rather than claiming the issue is fully fixed.
  • A Japanese modifier arriving after the 300 ms hold window converges by sending DEL followed by the corrected grapheme. This mirrors the existing live Hangul replacement tradeoff and is covered by regression tests.
  • The full iOS app-scheme failure is outside this diff: after overriding older Pod deployment targets to iOS 15.1, Xcode 27 stops in the existing Expo Router LinkPreviewNativeActionView.swift because subtitle requires iOS 16.

ELI5

Japanese IME on mobile terminal could send composing text and break kana modifiers. Composing text stays local until committed, Enter is not double-sent, and Hangul behavior is preserved.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a cross-platform Expo terminal input package with Android and iOS native views that handle committed text, IME composition, Enter, focus, blur, and backspace events. The session route now uses the shared TerminalLiveInputView and capture-handle contract. Terminal composition mirroring is generalized from Hangul to include Japanese kana modifiers, with updated mirror and hook tests covering delayed commits and corrective deletion payloads.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely matches the main mobile IME composition fix.
Description check ✅ Passed All required sections are present and substantive, including summary, screenshots, testing, AI review, security, and notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
mobile/packages/expo-terminal-live-input/android/src/main/java/expo/modules/terminalliveinput/TerminalLiveInputView.kt (2)

259-278: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Deduplicate the two deleteSurroundingText* overrides.

Both overrides share the identical empty-field guard and only differ in which super method they call. Extract a small private helper to avoid the two copies drifting.

♻️ Proposed refactor
+    private fun handleDeleteAtEmpty(beforeLength: Int): Boolean {
+      val current = editText.text?.toString() ?: ""
+      if (current.isEmpty() && beforeLength > 0) {
+        onKeyPress(mapOf("key" to "Backspace"))
+        return true
+      }
+      return false
+    }
+
     override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean {
-      val current = editText.text?.toString() ?: ""
-      if (current.isEmpty() && beforeLength > 0) {
-        onKeyPress(mapOf("key" to "Backspace"))
-        return true
-      }
-      return super.deleteSurroundingText(beforeLength, afterLength)
+      if (handleDeleteAtEmpty(beforeLength)) return true
+      return super.deleteSurroundingText(beforeLength, afterLength)
     }

     override fun deleteSurroundingTextInCodePoints(
       beforeLength: Int,
       afterLength: Int
     ): Boolean {
-      val current = editText.text?.toString() ?: ""
-      if (current.isEmpty() && beforeLength > 0) {
-        onKeyPress(mapOf("key" to "Backspace"))
-        return true
-      }
-      return super.deleteSurroundingTextInCodePoints(beforeLength, afterLength)
+      if (handleDeleteAtEmpty(beforeLength)) return true
+      return super.deleteSurroundingTextInCodePoints(beforeLength, afterLength)
     }

186-207: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Name the shared ~50ms IME-confirm heuristic window instead of repeating it as a magic literal per platform. Both platforms independently hardcode the same "dedupe/suppress Enter around IME confirmation" timing window without a shared, documented constant, risking silent drift if one side is tuned without the other.

  • mobile/packages/expo-terminal-live-input/android/src/main/java/expo/modules/terminalliveinput/TerminalLiveInputView.kt#L186-L207: extract the two 50L occurrences (armTerminalEnterDispatchGuard, armSuppressTerminalEnter) into one named constant (e.g. a companion object IME_ENTER_HEURISTIC_WINDOW_MS).
  • mobile/packages/expo-terminal-live-input/ios/TerminalLiveInputView.swift#L91-L135: extract the 0.05 literal in armTerminalEnterSuppression into a similarly named constant, and consider documenting that it should track the Android value.
mobile/packages/expo-terminal-live-input/expo-module.config.json (1)

2-5: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Use apple for module registration instead of ios.

Keep "ios" in "platforms" if needed, but move the module list to the documented Apple config key:

"apple": { "modules": ["ExpoTerminalLiveInputModule"] }

This avoids relying on legacy iOS-specific module config syntax and keeps the package consistent with the current Expo module config.

mobile/packages/expo-terminal-live-input/src/ExpoTerminalLiveInput.types.ts (1)

31-40: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Model native async functions on the ref, not as JSX props.

Expo View AsyncFunctions are attached to the React ref. Declaring focusAsync, blurAsync, and setTextAsync as optional props makes the bridge contract misleading and leaves the actual native ref API untyped. Define a separate native ref handle and use it when typing the wrapper’s native ref. (docs.expo.dev)

Proposed type split
+export type NativeTerminalLiveInputViewHandle = {
+  focusAsync: () => Promise<boolean>
+  blurAsync: () => Promise<boolean>
+  setTextAsync: (text: string) => Promise<void>
+}
+
 export type NativeTerminalLiveInputViewProps = ViewProps & {
   readonly editable?: boolean
   readonly onCommittedText?: (event: TerminalLiveInputCommittedTextEvent) => void
   readonly onInputFocus?: (event: TerminalLiveInputFocusEvent) => void
   readonly onInputBlur?: (event: TerminalLiveInputFocusEvent) => void
   readonly onKeyPress?: (event: TerminalLiveInputKeyPressEvent) => void
   readonly onTerminalEnter?: (event: TerminalLiveInputTerminalEnterEvent) => void
-  readonly focusAsync?: () => Promise<boolean>
-  readonly blurAsync?: () => Promise<boolean>
-  readonly setTextAsync?: (text: string) => Promise<void>
 }

Source: MCP tools


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 206d789c-2e57-4772-a1d5-dec0f99b393d

📥 Commits

Reviewing files that changed from the base of the PR and between 8a23618 and f94b83b.

⛔ Files ignored due to path filters (1)
  • mobile/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (27)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/package.json
  • mobile/packages/expo-terminal-live-input/android/build.gradle
  • mobile/packages/expo-terminal-live-input/android/src/main/AndroidManifest.xml
  • mobile/packages/expo-terminal-live-input/android/src/main/java/expo/modules/terminalliveinput/ExpoTerminalLiveInputModule.kt
  • mobile/packages/expo-terminal-live-input/android/src/main/java/expo/modules/terminalliveinput/TerminalLiveInputView.kt
  • mobile/packages/expo-terminal-live-input/expo-module.config.json
  • mobile/packages/expo-terminal-live-input/ios/ExpoTerminalLiveInput.podspec
  • mobile/packages/expo-terminal-live-input/ios/ExpoTerminalLiveInputModule.swift
  • mobile/packages/expo-terminal-live-input/ios/TerminalLiveInputView.swift
  • mobile/packages/expo-terminal-live-input/package.json
  • mobile/packages/expo-terminal-live-input/src/ExpoTerminalLiveInput.types.ts
  • mobile/packages/expo-terminal-live-input/src/ExpoTerminalLiveInputModule.ts
  • mobile/packages/expo-terminal-live-input/src/ExpoTerminalLiveInputModule.web.ts
  • mobile/packages/expo-terminal-live-input/src/TerminalLiveInputView.tsx
  • mobile/packages/expo-terminal-live-input/src/index.ts
  • mobile/packages/expo-terminal-live-input/tsconfig.json
  • mobile/src/terminal/terminal-live-composition-mirror.test.ts
  • mobile/src/terminal/terminal-live-composition-mirror.ts
  • mobile/src/terminal/terminal-live-hangul-mirror.ts
  • mobile/src/terminal/terminal-live-ime-native-contract.test.ts
  • mobile/src/terminal/terminal-live-input-affordance.test.ts
  • mobile/src/terminal/terminal-live-input-capture-handle.ts
  • mobile/src/terminal/use-terminal-live-accessory-input-commit.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-pending-input-flush.ts
💤 Files with no reviewable changes (1)
  • mobile/src/terminal/terminal-live-hangul-mirror.ts

@AmethystLiang
AmethystLiang requested a review from OrcaWin July 24, 2026 16:51
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
mobile/src/terminal/terminal-live-input-fallback.test.ts (1)

2-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid adding new tests with deprecated react-test-renderer.

This package is deprecated in React 19, and suppressing the deprecation warning hides the React migration signal. Prefer the project’s supported React Native testing harness instead.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2dee70f9-6381-44a5-81b7-028e717335ff

📥 Commits

Reviewing files that changed from the base of the PR and between f94b83b and 8453378.

📒 Files selected for processing (2)
  • mobile/packages/expo-terminal-live-input/src/TerminalLiveInputView.tsx
  • mobile/src/terminal/terminal-live-input-fallback.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/packages/expo-terminal-live-input/src/TerminalLiveInputView.tsx

Comment on lines +30 to +36
beforeEach(() => {
globalThis.IS_REACT_ACT_ENVIRONMENT = true
})

afterEach(() => {
act(() => renderer?.unmount())
renderer = null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the target test file and nearby global flag usage.
printf 'Files:\n'
git ls-files | grep -F 'mobile/src/terminal/terminal-live-input-fallback.test.ts' || true

printf '\nTest file excerpt:\n'
if [ -f mobile/src/terminal/terminal-live-input-fallback.test.ts ]; then
  nl -ba mobile/src/terminal/terminal-live-input-fallback.test.ts | sed -n '1,80p'
fi

printf '\nGlobal IS_REACT_ACT_ENVIRONMENT usages:\n'
rg -n "IS_REACT_ACT_ENVIRONMENT|beforeEach|afterEach" mobile/src/terminal --glob '*.test.ts' || true

printf '\nAll repository usages (concise):\n'
rg -n "IS_REACT_ACT_ENVIRONMENT|beforeEach|afterEach" --glob '*.test.ts' --glob '*.tsx' --glob '*.ts' . | head -200 || true

Repository: stablyai/orca

Length of output: 276


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE=mobile/src/terminal/terminal-live-input-fallback.test.ts

printf 'Target file exists and line count:\n'
wc -l "$FILE" || true

printf '\nTarget file excerpt with line numbers:\n'
awk '{printf "%6d\t%s\n", NR, $0}' "$FILE" | sed -n '1,90p'

printf '\nRepository IS_REACT_ACT_ENVIRONMENT usages:\n'
rg -n "IS_REACT_ACT_ENVIRONMENT" . | sed -n '1,200p' || true

Repository: stablyai/orca

Length of output: 12936


Restore IS_REACT_ACT_ENVIRONMENT in this suite.

This test mutates the process-global React act flag in beforeEach and never writes it back, so later tests can inherit the changed act warning behavior depending on run order. Capture the prior value before assigning and restore it in afterEach.

@OrcaWin

OrcaWin commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the substantial native IME work. We reproduced the original Japanese failure in a source-built iOS app, audited both f94b83b and the newer 8453378 head, and confirmed the latest fallback-Enter commit does not change the native causal path. The remaining design cannot deterministically distinguish intentional ASCII s from the provisional first key of Japanese sa: iOS exposes the same unmarked text callback for both, so immediate delivery corrupts sa to さ while the 300 ms hold makes correctness depend on timing. The 50 ms Enter/dedupe windows, corrective DEL after PTY delivery, lifecycle clearing, and unacknowledged send queue likewise leave slow-device, reconnect, grapheme, Korean-rewrite, and Android behavior unproved. The native event-name collision finding is valid, but it does not make the text-delivery contract safe. We need a replacement built around native revisioned editor transactions and one acknowledged, idempotent input queue shared with #7094 and composed with #10447, followed by physical iOS/Android/Korean matrices. Closing this PR rather than asking for more timer tuning; a replacement PR that proves that lifecycle contract would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants