Skip to content

fix(mobile): decide terminal preedit from the marked-text range, not a script table - #15007

Merged
nwparker merged 2 commits into
mainfrom
nwparker/mobile-preedit-composing
Aug 17, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/mobile-preedit-composing

Conversation

@nwparker

@nwparker nwparker commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​386 $\color{#cf222e}{\Huge{\mathbf{−}}}$​212 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​174
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​182 $\color{#cf222e}{\Huge{\mathbf{−}}}$​79 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103

Fixes #7427. Supersedes #13070 and #12341, and adopts the necessary half of #11450 with credit.

Root cause: a script allowlist, again

terminal-live-hangul-mirror.ts decided what to withhold from the pty with a four-range Hangul codepoint allowlist, and held exactly one trailing code point. Both halves are Hangul-specific tricks dressed as general rules:

  • The allowlist has no kana or kanji, so a Japanese reading streams to the shell and is repaired afterwards with DEL bytes — the reported sあ instead of さ.
  • The single-code-point hold is only correct because Hangul composition mutates just the trailing syllable. きょう is a three-code-point reading, so adding kana to the table still leaks きょ.

This is the same antipattern the desktop terminal already removed: a 23-term input-source allowlist plus a 30-character punctuation table, replaced by a structural rule that reads key for length only, never identity.

The counterexample that settles it

Chinese pinyin preedit is plain ASCII. n → ni → niha → nihao → 你好.

No codepoint rule of any kind can tell that from someone typing nihao at a shell prompt. That single fact refutes every table-based approach, including the one shipped today and the one #13070 proposes. It is now a test.

The structural signal

The text system's marked-text / composing range, delivered per change — never a property of the characters:

  • composing === true → hold the entire unsent suffix, any length, any script. The settle timer is not armed: preedit is not text yet, so nothing may promote it on a timer. Explicit boundaries still flush.
  • composing === false → hold nothing; zero-latency echo, unchanged.
  • composing === undefined (platform reports no range) → hold the trailing non-ASCII run. Enumerates nothing, covers kana/kanji/Hangul/Cyrillic, and ASCII keeps zero lag. Honest limitation: it cannot see an ASCII preedit.

isTerminalLiveHangulCodePoint and its four ranges are deleted. The file is renamed because the old name enshrined the antipattern.

The wiring change that made the signal visible at all: onChangeText → onChange. onChangeText hands over a bare string and throws the report away.

Why a React Native patch is genuinely required

Upstream RN 0.83.9 does not expose composition state — _textInputMetrics in RCTTextInputComponentView.mm has no such field. #11450's premise is correct and its patch is necessary; it is adopted here, regenerated cleanly via pnpm patch against pristine 0.83.9, with @brennanb2025 credited as co-author.

It takes effect because the app already sets expo-build-properties.ios.buildReactNativeFromSource: true, so iOS compiles RN from node_modules.

Android cannot be fixed this way and nobody should try. RN Android has no composing flag anywhere (ReactTextChangedEvent carries text + eventCount only), and Android consumes the prebuilt react-android Maven AAR — a Kotlin patch in node_modules is never compiled. That asymmetry is exactly why the undefined fallback exists.

What reference terminals do

Neither gates on script — grepping both input paths for 0x1100 / 0xAC00 / 0x3040 / 0x4E00 returns zero hits. One tests markedTextRange.length > 0 and consumes the key; the other carries a composing: bool on the key event and returns early before encoding, with a comment whose worked example is Japanese. In both, preedit is never sent and commit is the only thing that reaches the pty. Neither has any "send it, then repair with DEL" concept — which is why the DEL machinery here survives only as the Android no-report fallback.

Verdicts on the other PRs

PR
#13070 Close — adds a second script allowlist beside the Hangul one, and asserts kanji commits immediately, which is false since candidates are re-convertible. Cannot ever handle pinyin.
#11450 The patch file is the right piece and is taken here. Its JS half leaves the Hangul allowlist and DEL repair in place on the non-composing path.
#12341 Close the branch, keep the idea — its Android native ViewManager is the only thing that could work there, but it is 28 files and 805 commits behind.
#11246 Not subsumed — merge separately. iOS NFD→NFC is orthogonal; this helps incidentally by holding all three decomposed jamo, but the committed bytes are still NFD without that one-liner.

Proof the test discriminates

Restored main's algorithm behind the new signature, kept the new tests:

FAIL > Japanese romaji, marked-text range reported
  expected [ 's', '\x7fさ', 'く', 'ら', …(1) ] to deeply equal [ '桜' ]

FAIL > ASCII Chinese pinyin preedit
  expected [ 'n', 'i', 'ha', 'o', …(1) ] to deeply equal [ '你好' ]

The first is #7427 reproduced at the hook level, DEL repair and all. 10 tests fail on the old algorithm; all pass on the new one.

Size

Application production TS: +122 / −79 = net +43. Not net-negative, and I won't pretend otherwise — roughly 14 lines are the rationale comment and ~20 are formatter-expanded signatures for threading one optional parameter. What it does buy is that there is now exactly one hold rule with one input, instead of a table that needs extending per script. Plus the vendored patch (+48), package.json (+3), lockfile (+5, hand-limited to the patchedDependencies block — pnpm's rewrite had dragged in ~470 lines of unrelated dependency churn).

Verified

450 files / 3560 tests pass, 3 skipped. tsc --noEmit, oxlint, oxfmt --check clean. pnpm install --frozen-lockfile succeeds and the patch lands in node_modules — I re-verified that independently.

Not verified — needs a device

  • No IME ever drove this. Coverage is model- and hook-level only.
  • The iOS patch has not been compiled. It applies to pristine 0.83.9 and buildReactNativeFromSource is set; the app was not built.
  • Whether isComposing is false versus absent on Android at runtime. Read from RN source, not observed. If Android ever delivered false, the fallback would be bypassed and Korean would regress there — first thing to check on a device.
  • Android Korean now commits 한글 as one unit at the settle timer rather than streaming 한 then 글. Safer, fewer DELs, less live. Unvalidated against a real Gboard IME.

A note for anyone hoping #13366 closes the device gap: it does not. It is a build/boot/lifecycle harness; its own docs say a Play Store image and hand-configuration are needed for a CJK keyboard. Useful for manual repro, but it will not produce an automated romaji or flick test.


Readiness review — one P1 found and fixed

The supply-chain check came back cryptographically clean, verified rather than asserted: the patch's pre-image blob hashes match the pristine npm tarball exactly, its post-image hashes match what is installed, a full recursive diff of pristine-vs-installed React Native shows exactly the three files the patch names and nothing else, and the lockfile's integrity hash is the true SHA-256 of the patch file. It adds one optional boolean — no scripts, no hooks, no network, no binaries — and it genuinely reaches the iOS binary via buildReactNativeFromSource: true and a local CocoaPods build.

P1, now fixed: the composing === undefined branch walked the trailing non-ASCII run over the whole field and ignored stableLength, unlike the reported branch directly above it. After a settle-timer commit, the next keystroke re-held everything already delivered, and the caller erased it with DEL and retyped it.

Measured: a nine-character Cyrillic word produced a DEL per already-sent character. Worse, the DELs go out immediately while the re-send waits 300 ms — and in that window the held text is the only copy, so a connection blip, tab switch, or keyboard toggle left the word erased from the prompt and dropped from the field, destroying characters the pty already had. On main that was structurally impossible, since the hold was one Hangul code point.

Bounded the fallback the same way the reported branch is bounded. All nine original vectors still pass. Pinned by a new test that drives a settle commit between every keystroke and asserts no DEL reaches the wire; without the bound it fails with п\x7fпр\x7f\x7fпри….

Correction to this PR body: the earlier claim that Android Korean produces "fewer DELs" was measurably backwards before this fix. With the bound it is now true — zero DELs for the non-composing case.

Follow-up, not fixed here (P2): use-terminal-live-accessory-input-commit.ts types applyLiveInputMirror with two parameters and drops the new composing argument, so an accessory Backspace during a reported iOS composition takes the fallback branch and arms the settle timer — the one thing this design forbids. It is not a regression from main, which leaked there too, and the right value for the accessory to pass is a design question rather than a mechanical thread-through, so it is deliberately left for its own change.

…a script table

The live terminal capture field decided what to withhold from the PTY with a
Unicode-block allowlist (Hangul jamo and syllables) and held exactly one trailing
code point. Kana and kanji are not in the table, so a Japanese reading streamed to
the PTY one fragment at a time and was repaired afterwards with DEL bytes (#7427).

A code-point table cannot work, and the counterexample is not exotic: Chinese
pinyin preedit is plain ASCII, and a Japanese romaji reading is one code point on
the first keystroke and three on the fourth. Preedit is a property of the FIELD,
not of the characters in it, so the only signal that identifies it is the text
system's marked-text range. That is what a reference terminal implementation uses
on every platform it supports - `hasMarkedText` there, the input-method context's
composing state elsewhere - and neither one classifies code points anywhere in the
input path.

So the mirror now takes the marked-text report per change and holds the whole
preedit region, whatever its length or script:
- Subscribe the capture field to `onChange`, not `onChangeText`; only the raw
  native event carries the report at all.
- A reported preedit is held entire and is never committed by the settle timer,
  because preedit is not text yet. Explicit boundaries still flush it.
- `isTerminalLiveHangulCodePoint` and its four ranges are deleted.

iOS reports the range but React Native drops it before JS, so the pinned patch
forwards `markedTextRange` into the change payload. It is three hunks and it
compiles because the app already sets `buildReactNativeFromSource` for iOS. The
same idea was proposed in #11450, which is where the patch comes from.

Android has no marked-text report in React Native at all, and a Kotlin patch would
not help: Android consumes the prebuilt react-android artifact, so node_modules
sources are never compiled. Until the report exists there, the fallback holds the
trailing non-ASCII run. It enumerates nothing, it covers kana, kanji and Hangul,
and ASCII keeps its zero-latency echo - but it cannot see an ASCII preedit, so
Chinese pinyin on Android still leaks its reading. Only a report fixes that.

Not-tested: no physical device or emulator was available, so no real IME drove
this path. Japanese, Chinese and Korean composition are covered at the model and
hook level only, and the iOS patch has not been compiled.

Co-authored-by: Brennan Benson <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The live terminal input now receives native change events with composition state. A React Native patch reports marked-text status through Fabric text input events. Terminal mirroring now handles reported and inferred preedit text, computes deletion and append operations, and delays commits only when composition state is unknown. Tests cover Japanese, Chinese, Hangul, Vietnamese, ASCII, corrections, deletions, commits, and input lifecycle behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the change, root cause, linked issue, testing, limitations, and follow-up, but omits required template sections including Visual Proof and Checklist. Add the missing template sections, especially Visual Proof with an attachment or N/A justification, plus Testing checkboxes, AI Disclosure, Review, Notes, Agent skill boundary, Checklist, and Author.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #7427 by preserving Japanese preedit text, forwarding committed input once, and adding regression coverage.
Out of Scope Changes check ✅ Passed The RN patch, Android fallback, Hangul removal, and broader IME tests support the linked issue’s composition-handling objective.
Title check ✅ Passed The title clearly identifies the main change: replacing script-based terminal preedit detection with marked-text range detection.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

🧹 Nitpick comments (1)
mobile/src/terminal/terminal-live-preedit-mirror.ts (1)

16-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten the preedit fallback comment.

Keep the invariant near heldPreeditLength. Move the detailed platform and behavior explanation to focused documentation if it must remain.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”

Proposed comment reduction
-/**
- * How much of the field the text system can still rewrite, in code points.
- *
- * Preedit is a fact about the field, never about the script — Chinese pinyin
- * preedit is plain ASCII — so the marked-text range decides and no code point is
- * ever classified. That is what makes this hold for input methods nobody tested.
- *
- * `composing` is undefined only where the platform reports no range at all —
- * today React Native Android. The fallback holds the trailing non-ASCII run: a
- * conversion IME always leaves one and ASCII keeps its zero-latency echo. It
- * enumerates nothing, and it cannot see an ASCII preedit — only a report can.
- */
+// Hold reported preedit; without a report, hold the trailing non-ASCII run.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41b04128-2cc4-4618-b7b4-4adf46056c8a

📥 Commits

Reviewing files that changed from the base of the PR and between 71bbab7 and ff3140f.

⛔ Files ignored due to path filters (1)
  • mobile/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/package.json
  • mobile/patches/[email protected]
  • mobile/src/terminal/terminal-ios-ime-keyboard.test.ts
  • mobile/src/terminal/terminal-live-hangul-mirror.test.ts
  • mobile/src/terminal/terminal-live-hangul-mirror.ts
  • mobile/src/terminal/terminal-live-preedit-mirror.test.ts
  • mobile/src/terminal/terminal-live-preedit-mirror.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 (2)
  • mobile/src/terminal/terminal-live-hangul-mirror.test.ts
  • mobile/src/terminal/terminal-live-hangul-mirror.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.

The no-report branch walked the trailing non-ASCII run over the whole field and
ignored stableLength, unlike the reported branch directly above it. So after a
settle-timer commit the next keystroke re-held everything already delivered and
the caller erased it with DEL and retyped it — a nine-character Cyrillic word
cost a DEL per already-sent character, and for the 300ms before the re-send the
held text was the only copy, so a blur or reconnect destroyed characters the pty
already had.

Bound it the way the reported branch is bounded. Pinned by a test that drives a
settle commit between every keystroke and asserts no DEL reaches the wire.

@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.

🧹 Nitpick comments (1)
mobile/src/terminal/terminal-live-preedit-mirror.ts (1)

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

Use concise comments in the preedit mirror changes.

  • mobile/src/terminal/terminal-live-preedit-mirror.ts#L44-L47: replace the four-line explanation with one comment that states the sent-text invariant.
  • mobile/src/terminal/terminal-live-preedit-mirror.test.ts#L259-L285: retain one Android-specific comment and remove redundant rationale and BDD labels.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9994deb0-9f48-45ce-8059-e6ca3a925c97

📥 Commits

Reviewing files that changed from the base of the PR and between ff3140f and 7f51014.

📒 Files selected for processing (2)
  • mobile/src/terminal/terminal-live-preedit-mirror.test.ts
  • mobile/src/terminal/terminal-live-preedit-mirror.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 1 remains after this review.

@nwparker
nwparker merged commit 66b5993 into main Aug 17, 2026
46 checks passed
@nwparker
nwparker deleted the nwparker/mobile-preedit-composing branch August 17, 2026 07:01
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…a script table (stablyai#15007)

* fix(mobile): decide terminal preedit from the marked-text range, not a script table

The live terminal capture field decided what to withhold from the PTY with a
Unicode-block allowlist (Hangul jamo and syllables) and held exactly one trailing
code point. Kana and kanji are not in the table, so a Japanese reading streamed to
the PTY one fragment at a time and was repaired afterwards with DEL bytes (stablyai#7427).

A code-point table cannot work, and the counterexample is not exotic: Chinese
pinyin preedit is plain ASCII, and a Japanese romaji reading is one code point on
the first keystroke and three on the fourth. Preedit is a property of the FIELD,
not of the characters in it, so the only signal that identifies it is the text
system's marked-text range. That is what a reference terminal implementation uses
on every platform it supports - `hasMarkedText` there, the input-method context's
composing state elsewhere - and neither one classifies code points anywhere in the
input path.

So the mirror now takes the marked-text report per change and holds the whole
preedit region, whatever its length or script:
- Subscribe the capture field to `onChange`, not `onChangeText`; only the raw
  native event carries the report at all.
- A reported preedit is held entire and is never committed by the settle timer,
  because preedit is not text yet. Explicit boundaries still flush it.
- `isTerminalLiveHangulCodePoint` and its four ranges are deleted.

iOS reports the range but React Native drops it before JS, so the pinned patch
forwards `markedTextRange` into the change payload. It is three hunks and it
compiles because the app already sets `buildReactNativeFromSource` for iOS. The
same idea was proposed in stablyai#11450, which is where the patch comes from.

Android has no marked-text report in React Native at all, and a Kotlin patch would
not help: Android consumes the prebuilt react-android artifact, so node_modules
sources are never compiled. Until the report exists there, the fallback holds the
trailing non-ASCII run. It enumerates nothing, it covers kana, kanji and Hangul,
and ASCII keeps its zero-latency echo - but it cannot see an ASCII preedit, so
Chinese pinyin on Android still leaks its reading. Only a report fixes that.

Not-tested: no physical device or emulator was available, so no real IME drove
this path. Japanese, Chinese and Korean composition are covered at the model and
hook level only, and the iOS patch has not been compiled.

Co-authored-by: Brennan Benson <[email protected]>

* fix(mobile): bound the fallback hold to text the pty has not received

The no-report branch walked the trailing non-ASCII run over the whole field and
ignored stableLength, unlike the reported branch directly above it. So after a
settle-timer commit the next keystroke re-held everything already delivered and
the caller erased it with DEL and retyped it — a nine-character Cyrillic word
cost a DEL per already-sent character, and for the 300ms before the re-send the
held text was the only copy, so a blur or reconnect destroyed characters the pty
already had.

Bound it the way the reported branch is bounded. Pinned by a test that drives a
settle commit between every keystroke and asserts no DEL reaches the wire.

---------

Co-authored-by: Brennan Benson <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…a script table (stablyai#15007)

* fix(mobile): decide terminal preedit from the marked-text range, not a script table

The live terminal capture field decided what to withhold from the PTY with a
Unicode-block allowlist (Hangul jamo and syllables) and held exactly one trailing
code point. Kana and kanji are not in the table, so a Japanese reading streamed to
the PTY one fragment at a time and was repaired afterwards with DEL bytes (stablyai#7427).

A code-point table cannot work, and the counterexample is not exotic: Chinese
pinyin preedit is plain ASCII, and a Japanese romaji reading is one code point on
the first keystroke and three on the fourth. Preedit is a property of the FIELD,
not of the characters in it, so the only signal that identifies it is the text
system's marked-text range. That is what a reference terminal implementation uses
on every platform it supports - `hasMarkedText` there, the input-method context's
composing state elsewhere - and neither one classifies code points anywhere in the
input path.

So the mirror now takes the marked-text report per change and holds the whole
preedit region, whatever its length or script:
- Subscribe the capture field to `onChange`, not `onChangeText`; only the raw
  native event carries the report at all.
- A reported preedit is held entire and is never committed by the settle timer,
  because preedit is not text yet. Explicit boundaries still flush it.
- `isTerminalLiveHangulCodePoint` and its four ranges are deleted.

iOS reports the range but React Native drops it before JS, so the pinned patch
forwards `markedTextRange` into the change payload. It is three hunks and it
compiles because the app already sets `buildReactNativeFromSource` for iOS. The
same idea was proposed in stablyai#11450, which is where the patch comes from.

Android has no marked-text report in React Native at all, and a Kotlin patch would
not help: Android consumes the prebuilt react-android artifact, so node_modules
sources are never compiled. Until the report exists there, the fallback holds the
trailing non-ASCII run. It enumerates nothing, it covers kana, kanji and Hangul,
and ASCII keeps its zero-latency echo - but it cannot see an ASCII preedit, so
Chinese pinyin on Android still leaks its reading. Only a report fixes that.

Not-tested: no physical device or emulator was available, so no real IME drove
this path. Japanese, Chinese and Korean composition are covered at the model and
hook level only, and the iOS patch has not been compiled.

Co-authored-by: Brennan Benson <[email protected]>

* fix(mobile): bound the fallback hold to text the pty has not received

The no-report branch walked the trailing non-ASCII run over the whole field and
ignored stableLength, unlike the reported branch directly above it. So after a
settle-timer commit the next keystroke re-held everything already delivered and
the caller erased it with DEL and retyped it — a nine-character Cyrillic word
cost a DEL per already-sent character, and for the 300ms before the re-send the
held text was the only copy, so a blur or reconnect destroyed characters the pty
already had.

Bound it the way the reported branch is bounded. Pinned by a test that drives a
settle commit between every keystroke and asserts no DEL reaches the wire.

---------

Co-authored-by: Brennan Benson <[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]: Orca Mobile terminal cannot enter Japanese via flick or romaji IME

1 participant