Skip to content

fix(terminal): compose Hangul on iPadOS by mirroring field edits to the PTY - #13346

Closed
dvpaa wants to merge 3 commits into
stablyai:mainfrom
dvpaa:fix/ipados-terminal-hangul-text-edit-mirror
Closed

dvpaa wants to merge 3 commits into
stablyai:mainfrom
dvpaa:fix/ipados-terminal-hangul-text-edit-mirror

Conversation

@dvpaa

@dvpaa dvpaa commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Korean typed on an iPadOS hardware keyboard reached the terminal as uncomposed
compatibility jamo in the orca serve web client — 한글깨짐 arrived as
ㅎㅏㄴㄱㅡㄹㄲㅐㅈㅣㅁ. It reproduces in both Safari and Chrome, which share the
system WebKit engine on iOS.

iPadOS composes Hangul with a hardware keyboard by rewriting text it has
already committed
— deleteContentBackward followed by insertText carrying
the updated syllable — and fires no composition events at all. xterm consumed the
printable keydown and default-prevented it, so that logic never ran and the raw
jamo from event.key went to the PTY.

Captured on iPadOS 26.5.2, an ordinary text field on the same page shows the
working path and the terminal shows the broken one, from identical keydowns:

keystroke ordinary text field terminal
ㅎ input insertText "ㅎ" (U+314E) keydown/keyup only
ㅏ deleteContentBackward → insertText "하" (U+D558) keydown/keyup only
ㄴ deleteContentBackward → insertText "한" (U+D55C) keydown/keyup only

Exactly one key escaped in the terminal capture: ㄲ, typed with Shift, which
matched the existing Shift bypass in xterm-bypass-policy.ts and produced the
full native keypress/beforeinput/input chain. That bypass is the control
group proving the mechanism.

Fixes #13345

What this changes

  1. On iOS/iPadOS, generalize that bypass to unmodified non-ASCII printable keys,
    keypress included — without it _keyPress re-sends the glyph alongside the
    mirror.
  2. Mirror the resulting field edits to the PTY as DEL × n + replacement, using
    the prefix-diff approach the mobile client already uses in
    terminal-live-hangul-mirror.ts.

Diffing the field rather than replaying edit events keeps a stray delete from
desyncing the PTY, and handles the non-1:1 case: typing ㅣ after 깾 emits one
deletion and reinserts two characters.

Input sources that do run a composition session — the on-screen keyboard, the
Japanese and Chinese IMEs — are left entirely to xterm's CompositionHelper,
which already commits them correctly.

Not affected

No non-iOS platform. shouldBypassXtermForIosTextEdit returns early when the
flag is off, so desktop IME handling is untouched. In particular the macOS
native-text forwarder stays installed — deleting it is what regressed full-width
CJK punctuation in #13128 and forced the revert in #13282.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build — build:desktop and both native scripts pass individually; the
    build:native wrapper cannot run on this machine, see below
  • Added or updated high-quality tests that would catch regressions

36 new tests across 3 files. The core one replays the 19-step field sequence
recorded on the affected device and asserts the PTY renders 한글깨짐 with no
compatibility jamo left over, so a regression fails the test rather than
silently degrading. All 651 test files under terminal-pane/ and lib/ pass.

pnpm test reports 5 pre-existing failures on this machine
(check-root-directory-entries, terminal-attribution, runtime-auth-service,
updater, remote-runtime-shared-control-connection). They reproduce
identically on main at 34f2a62 and live in config/scripts/, src/main/
and src/shared/ — this change touches only src/renderer/.

pnpm build could not complete on this machine: build:native re-invokes pnpm
as node $npm_execpath run <script>
(config/scripts/build-native-for-platform.mjs:19-27), which assumes a
JavaScript entry point. With pnpm installed as the standalone @pnpm/exe
binary, Node parses that binary as JS and throws
SyntaxError: Invalid or unexpected token. This reproduces on main at
34f2a62 and CI is unaffected, since pnpm/action-setup installs the JS
distribution. Everything the wrapper would have run passes on its own:
build:desktop, build:computer-macos and build:notification-status-macos
all exit 0.

Device-verified on iPad Pro 12.9" (6th gen) / iPadOS 26.5.2 with a hardware
keyboard, against orca serve on Linux.

AI Review Report

Ran /code-review (high) and /security-review on the branch. The review
explicitly covered cross-platform compatibility for macOS, Linux and Windows —
shortcuts, labels, paths, shell behavior and Electron-specific differences —
plus SSH/remote/local, agent and integration compatibility, performance and
security risk.

Three findings were raised and fixed:

  1. Double-send on iOS input sources that do compose (high). The first draft
    intercepted input but not the composition events, so on the iPad on-screen
    keyboard or a Japanese IME the mirror sent preedit text and then xterm's
    _sendPendingComposition sent the same text again from the field, yielding
    にほんにほん. Fixed by standing aside for the whole composition session and
    adding an isComposing guard to the bypass predicate.
  2. Stale mirror state after a non-mirror PTY write (medium). reset() was
    hooked only to a non-bypassed keydown, so Ctrl+C, Cmd+V paste and the JIS-Yen
    branch each left sentText describing a line the shell no longer had; the
    next syllable rewrite then emitted DEL bytes against it. Replaced with a
    terminal.onData hook that resets on any write the mirror did not make,
    which covers all three plus xterm's own key handling.
  3. Unfiltered blur listener (low). Any focusable descendant blurring wiped
    mirror state and the field. Now filtered to the helper textarea, matching the
    input listener.

Cross-platform: the iOS branch is the only behavior change; every other
platform short-circuits before it. No shortcut, label, path or shell behavior is
touched, and nothing Electron-specific changes — this path only runs in the web
client.

SSH/remote/local: client-side input handling only. No RPC param, stream
frame or published content changes, so docs/reference/remote-wire-compatibility.md
does not apply. The mirror writes through terminal.input(), i.e. the existing
onData path, so the pane's replay guard, stale-agent block and mobile presence
lock all still run.

Agents and integrations: the bytes reaching the PTY are ordinary text plus
DEL (0x7f). No agent-, integration- or git-provider-specific branching.

Performance: one prefix comparison per input event, linear in the field
length and only while a CJK syllable is being composed. No new timers,
listeners on hot paths, or renders.

UI quality: no visual change.

Security Audit

/security-review found no HIGH or MEDIUM issues. Checked and ruled out:

  • PTY input guards are not bypassed. The mirror writes via
    terminal.input(), which lands on the same onData path as existing input,
    so the pane's guards still run.
  • Paste cannot reach the new input listener. TerminalPane.tsx registers
    a capture-phase paste listener on the pane-manager root and calls
    preventDefault(), so no default insertion and no input event occurs. The
    clipboard therefore still goes through the existing paste path rather than
    being forwarded raw.
  • Drag-and-drop likewise cannot reach it — the helper textarea sits at
    z-index: -5 and loses hit-testing.
  • No control-byte injection. The bypass requires codePoint >= 0x80 with no
    Ctrl/Meta/Alt, so no C0 byte or ESC can enter through it. The only control
    byte the mirror emits is DEL, and the count is bounded by the length of text
    the mirror itself sent.
  • stopImmediatePropagation() suppresses nothing security-relevant — only
    later-registered listeners on the same node, which is xterm's own input
    handling, by design.
  • No authentication, authorization, secrets, crypto, command-execution, path-
    handling or IPC surface is touched.

Notes

  • iOS/iPadOS detection needs two signals. Every iOS user agent contains
    Mac — Macintosh in iPad desktop mode, the default since iPadOS 13, and
    like Mac OS X in mobile mode — and desktop mode omits iPad, so
    maxTouchPoints is the only thing separating an iPad from a Mac.
  • Open question for reviewers: kitty keyboard. The sibling
    shouldBypassXtermForMacNativeText refuses to bypass while kitty progressive
    enhancement is active. The iOS branch deliberately does not, because gating on
    it would leave Korean broken in exactly the agent TUIs that enable kitty mode.
    Happy to add the guard if you would rather keep CSI-u reporting intact there.
  • Verified with a hardware keyboard only. The on-screen keyboard now routes
    through xterm's composition path rather than the mirror, but has not been
    device-tested. Chinese and Japanese IMEs on iPadOS are likewise untested.
  • The mirror sends DEL to repair a superseded syllable, the same tradeoff
    the mobile client already ships.
  • mobile/ is a separate pnpm workspace, so its equivalent mirror could not
    be imported directly; the shared algorithm is noted in the code comments
    instead of being extracted into a package, which felt out of scope here.

dvpaa added 2 commits August 10, 2026 01:31
…he PTY

Korean typed on an iPadOS hardware keyboard reached the terminal as
uncomposed compatibility jamo in the web client: `한글깨짐` arrived as
`ㅎㅏㄴㄱㅡㄹㄲㅐㅈㅣㅁ`. Both Safari and Chrome reproduce it, since iOS
bars third-party engines and both run system WebKit.

iPadOS composes Hangul with a hardware keyboard by rewriting text it has
already committed — `deleteContentBackward` then `insertText` with the
updated syllable — and fires no composition events at all. xterm consumed
the printable keydown and default-prevented it, so that logic never ran
and the raw jamo from `event.key` went to the PTY.

The terminal capture contains its own control group: `ㄲ`, typed with
Shift, matched the existing Shift bypass in xterm-bypass-policy.ts and
produced the full native keypress/beforeinput/input chain, while every
unmodified jamo produced keydown and keyup alone.

Generalize that bypass to unmodified non-ASCII printable keys on
iOS/iPadOS — keypress included, or _keyPress re-sends the glyph — and
mirror the resulting field edits to the PTY as DEL x n + replacement.
The diff is taken against the field rather than the edit events, so a
stray delete cannot desync the PTY and a replacement longer than what it
replaced still works: typing ㅣ after 깾 emits one deletion and reinserts
two characters.

Detection needs both signals. Every iOS user agent contains `Mac`
(`Macintosh` in iPad desktop mode, the default since iPadOS 13, and
`like Mac OS X` in mobile mode), and desktop mode omits `iPad`, so the
touch-point count is the only thing separating an iPad from a Mac.

No other platform changes: shouldBypassXtermForIosTextEdit returns early
when the flag is off. The macOS native-text forwarder stays installed —
deleting it is what regressed full-width CJK punctuation in stablyai#13128 and
forced the revert in stablyai#13282.

Tests replay the 19-step field sequence recorded on iPad Pro 12.9"
(6th gen) / iPadOS 26.5.2 and assert the PTY renders `한글깨짐` with no
compatibility jamo left over.
…external writes

Follow-up to the iPadOS Hangul mirror, closing three review findings.

The premise that iOS fires no composition events holds only for the
hardware Korean keyboard. The iPad on-screen keyboard and the Japanese
and Chinese IMEs do run a composition session, and xterm commits those
by reading the helper textarea — which the mirror deliberately does not
clear. Mirroring the preedit and then letting xterm commit the same
field sent the text twice (`にほん` arrived as `にほんにほん`). The mirror
now stands aside for the whole session and only clears its own
bookkeeping at compositionend; the field belongs to xterm. The bypass
predicate gains a matching isComposing guard.

Mirror state also went stale whenever something else wrote to the PTY.
reset() hung off a non-bypassed keydown, which Ctrl+C, Cmd+V paste and
the JIS-Yen branch all skip, so the next syllable rewrite emitted DEL
bytes against a line the shell no longer had. Replace it with a
terminal.onData hook that resets on any write the mirror did not make.

The blur listener is now filtered to the helper textarea, matching the
input listener, so an unrelated focusable descendant no longer wipes the
field mid-word.
@dvpaa
dvpaa marked this pull request as draft August 9, 2026 17:26
@dvpaa
dvpaa marked this pull request as ready for review August 9, 2026 17:28
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 98bd88c4-40bc-490a-8350-6a96b1e0a29a

📥 Commits

Reviewing files that changed from the base of the PR and between 099598d and 4b83063.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/terminal-ios-text-edit-mirror.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-text-edit-mirror.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/lib/ios-web-platform.test.ts
  • src/renderer/src/lib/ios-web-platform.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/renderer/src/lib/ios-web-platform.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-text-edit-mirror.test.ts
  • src/renderer/src/lib/ios-web-platform.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-text-edit-mirror.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts

📝 Walkthrough

Walkthrough

Adds iOS and iPadOS WebKit detection for mobile and desktop-mode iPads. Adds keyboard bypass rules for non-ASCII printable text during iOS editing. Adds a textarea mirror that converts Unicode edits into terminal erase bytes and appended text. Integrates the mirror with terminal lifecycle cleanup and terminal data resets. Adds tests for detection, keyboard handling, mirroring, composition, disposal, and edge cases.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 identifies the Hangul composition fix and the iPadOS PTY mirroring approach.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and platform-specific notes.
Linked Issues check ✅ Passed The implementation satisfies issue #13345 by detecting iOS, bypassing xterm, mirroring edits, preserving IME handling, and adding regression tests.
Out of Scope Changes check ✅ Passed The changes are limited to iOS detection, xterm bypass behavior, terminal edit mirroring, lifecycle integration, and related tests.

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: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 39081c7f-8f93-4b21-b3d5-234e7f946baa

📥 Commits

Reviewing files that changed from the base of the PR and between 34f2a62 and 099598d.

📒 Files selected for processing (7)
  • src/renderer/src/components/terminal-pane/terminal-ios-text-edit-mirror.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-text-edit-mirror.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy-ios.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
  • src/renderer/src/lib/ios-web-platform.test.ts
  • src/renderer/src/lib/ios-web-platform.ts

@nwparker

Copy link
Copy Markdown
Contributor

@dvpaa -- I'm just getting to this

  1. Is this still an issue?
  2. Could you show any videos/screenshots?

@nwparker

Copy link
Copy Markdown
Contributor

Thanks for this @dvpaa — and sorry for the slow review.

Your central architectural call is right, and it is the part we are keeping. The fix has to sit upstream of xterm-bypass-policy, because that policy is what decides which keys xterm ever sees. I had a competing PR (#15456) that patched xterm's vendored CompositionHelper instead, and it turns out to be broken precisely because it sits downstream of the policy: Orca's Shift bypass (xterm-bypass-policy.ts:261-271) hides ㄲ ㄸ ㅃ ㅆ ㅉ keydowns, so every syllable starting with a double consonant fails — 깨, 꿈, 딸, 빵, 쓰다, 짜다. Including 한글깨짐, the string from the issue. Your placement makes the source of the keydown irrelevant, which is the correct property.

Your iOS detection is also exactly right, and it is a trap others have fallen into: userAgent.includes('Mac') && maxTouchPoints > 1. Every iOS UA contains "Mac", and > 0 would misfire on a Mac with a touch peripheral. We verified it cannot misfire on desktop macOS.

We also confirmed Pinyin coexistence works with your bypass — driving a real Terminal: single commit → ['你'] exactly once, two in a row → ['你','好'], and both orderings interleaved with Korean. No double-handling with the composition tracker or candidate-key guards.

Two bugs we found by running the code, which is why we are not merging this as-is:

1. The terminal.write patch in the last commit (4b83063bfba) breaks the mirror. use-terminal-pane-lifecycle.ts:934-947 resets on any write it did not make — but PTY output goes through that same function, so every shell echo resets. Replaying your own recorded 19-step fixture with a shell echo after each keystroke:

expected: 한글깨짐
actual:   ㅎ하한한ㄱ한한그한한글한글ㄲ한글한글깨한글한글깾…

with zero DEL bytes emitted. The onData half of that fix is correct and sufficient; the write half is what kills it. Your device testing almost certainly predates this commit — nothing in the 36 tests touches the lifecycle wiring, which gained 36 lines with no coverage.

2. composing is a latch that can stick on. In terminal-ios-text-edit-mirror.ts:118-127 it is set on compositionstart and cleared only on compositionend. A composition that never ends — blur mid-composition, pane teardown, a cancelled IME — leaves it true for the life of the mirror, and mirrorTextEdit returns early forever. The blur listener calls reset() but does not clear it. Proved: compositionstart → blur → type the full sequence → nothing reaches the PTY.

That one is worse than it looks, because the bypass claims every unmodified non-ASCII key on iOS, so one stuck flag silently kills all non-ASCII typing on that pane — Cyrillic, Greek, kana — not just Korean. We shipped this exact bug class recently (a flag set but never expired disabled the Pinyin candidate-digit guard for a whole focus session), so we are being strict about it.

One design note, not a bug: send-then-retract puts 19 writes and 8 DEL bytes on the wire for 한글깨짐, where holding the syllable and committing only completed ones needs 3 writes and 0 DELs. DELs go to whatever is in raw mode — vim, an agent TUI — which need not treat 0x7f as "erase one cell", and each one is a round trip over SSH.

Where we landed: we are building a version that keeps your placement and bypass-policy extension, and holds the syllable in the renderer instead of retracting it. Your ios-web-platform.ts and shouldBypassXtermForIosTextEdit are being taken as-is, and you will be credited in the commit. I will link the PR here when it is up.

Also worth recording for anyone reading later: the merge conflict here is a non-issue — shouldBypassXtermForIosTextEdit and main's newer claimsOrphanCandidateDigit landed at the same line but are independent; keeping both, your 36 tests still pass alongside main's 4441.

@dvpaa

dvpaa commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and detailed explanation, @nwparker!

The breakdown of the two bugs (terminal.write reset and the sticky composing latch) makes total sense, and holding syllables in the renderer instead of sending DEL bytes is definitely a much cleaner and safer approach for TUIs and remote connections.

Glad to hear the bypass placement and iOS detection logic were helpful. Looking forward to the follow-up PR, and I'd be more than happy to test it on my iPad with the hardware keyboard once it's ready!

@nwparker nwparker removed the P0 label Aug 19, 2026
nwparker added a commit that referenced this pull request Aug 27, 2026
…enderer (#13345) (#15480)

* fix(terminal): compose iPadOS Hangul by holding the syllable in the renderer (#13345)

Korean typed on an iPad with a hardware keyboard reached the PTY as separate
jamo: `한글깨짐` arrived as `ㅎㅏㄴㄱㅡㄹ...`. iPadOS fires no composition
events for it — each jamo is a plain keydown while the IME rewrites the
syllable in place in the helper textarea — so xterm consumes the keydown, sends
the raw jamo from `_keyPress`, and drops the composed `insertText` because
`_inputEvent` admits a composed insert only when no key is down.

The jamo keydown is handed to the system by a new bypass rule, and the syllable
it builds is held in the renderer until the IME proves it final. The PTY sees
one write per syllable and nothing is ever sent then retracted, so raw-mode
TUIs never receive DEL bytes they need not read as "erase one cell" and SSH and
relay sessions pay no round trip for them. `한글깨짐` is four writes and zero
DELs.

Sitting upstream of `xterm-bypass-policy.ts` rather than inside xterm is what
makes this work for Shift-typed double consonants: Orca's own Shift rule
already hides `ㄲ ㄸ ㅃ ㅆ ㅉ` keydowns from xterm, so a fix living in
CompositionHelper never sees them and every syllable starting with one — 깨 꿈
딸 빵 쓰다 짜다 — stays broken. That placement call is dvpaa's, from #13346.

Composition sessions are left alone entirely, so Chinese pinyin on the same
device keeps working; that state is derived from the existing composition
tracker rather than latched, so a session that never ends cannot disable the
pane. The bypass claims jamo only — a Cyrillic or kana key would lose its
keydown, keypress and `input` alike and reach the PTY as nothing.

Co-authored-by: dvpaa <[email protected]>

* refactor(terminal): drop the dead session check from the iOS preedit input guard

`isCompositionOwnedInput(event) || options.isCompositionActive()` could never
take its second branch. The composition tracker's own `input` listener runs
first on the same element and clears its active flag for every input except
`insertCompositionText` — which is exactly the first disjunct. Verified by
construction: instrumented to throw on the combination, nothing in the renderer
suite (24k tests) reached it, and five deliberate attempts to build one, via a
resumed preedit and a post-compositionend insert, all failed to.

Reading composition ownership off the event alone also makes the decision
independent of listener registration order, which the previous comment at the
call site claimed to depend on. It does not: swapping the tracker and the
preedit controller leaves every test passing. The comment now states the one
coupling that is real — the controller stops propagation on `input` while a
syllable is held — without asserting a behavioral dependency that does not exist.

`isCompositionActive` remains the gate on opening a hold, where it is pinned.

* fix(terminal): settle iPad Hangul by diffing the field, not assuming it grows

The hold released a syllable only when the textarea tail grew past it and
still started with it. Korean batchim migration breaks that: a device
capture on iPadOS 26 shows `깨` + `ㅈ` rewritten to `깾` — a different
codepoint, not an extension — and only becoming `깨주` once the next vowel
decides where the `ㅈ` belongs. The prefix check failed there, the hold
stopped advancing, and `깨쥠` reached the PTY as one chunk on blur.

Locate the IME's edit with a prefix diff of the two field states instead.
Everything before where it began rewriting is settled: the batchim question
for those syllables is already answered. Still hold-and-commit, so no DEL
ever reaches the pty.

The capture is now the fixture, replayed both verbatim and as keystrokes.

* fix(terminal): keep the iPad Hangul hold open across the IME's erase rewrite

Backspace can decompose a held syllable as deleteContentBackward then a
replacing insertText, the same shape the IME uses to grow one. The hold
closed on the emptied half, so the replacement landed with nothing held:
typing 한, Backspace, ㄹ put a bare `ㄹ` on the wire and dropped 하.

The empty field now collapses the hold instead of closing it, and the
Backspace that finds nothing held is the one that reaches the PTY. An
`imeWrote` flag keeps an erased hold from resurrecting its opening jamo.

Also diff the field as NFC. Decomposed Hangul grows by appending jamo,
which the common-prefix diff reads as the previous syllable settling, so
an NFD source emitted one bare jamo per keystroke. The recorded device
trace is NFC, where normalization is a no-op.

* test(terminal): cover Japanese, Hanja and Greek on the iPad Hangul path

The coexistence suite proved pinyin and a short list of non-Hangul keys.
Widen it: a kana-to-kanji session, a Hanja lookup over a live preedit, a
digit that ends a held syllable as literal text, and Greek, halfwidth
kana and accented Latin among the keys the bypass must not claim.

---------

Co-authored-by: dvpaa <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor

Closing — #15480 has landed, and it keeps your architectural call.

The decision to fix this above the terminal rather than inside it was yours, and it is the part that survived. The competing approach patched the vendored xterm and, sitting downstream of Orca's own bypass policy, never fixed Shift-typed jamo — so every syllable starting with a double consonant (깨, 꿈, 딸, 빵) still broke, including 한글깨짐 from the issue. Your placement makes the origin of the keydown irrelevant, which is the correct property. Your ios-web-platform.ts detection (maxTouchPoints > 1, not > 0) was taken as-is.

You are credited as co-author on the merged change.

What differs: instead of mirroring field edits and retracting with DEL bytes, it holds the syllable and commits only what a common-prefix diff proves settled — 3 PTY writes and 0 DELs for 한글깨짐 rather than 19 and 8. That matters for raw-mode TUIs, which need not treat 0x7f as "erase one cell", and for SSH round trips.

Device-verified on a physical iPad against a recorded 34-event trace, which is committed as a fixture. Thanks for the PR and the review exchange — both changed the outcome.

@nwparker nwparker closed this Aug 27, 2026
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…enderer (stablyai#13345) (stablyai#15480)

* fix(terminal): compose iPadOS Hangul by holding the syllable in the renderer (stablyai#13345)

Korean typed on an iPad with a hardware keyboard reached the PTY as separate
jamo: `한글깨짐` arrived as `ㅎㅏㄴㄱㅡㄹ...`. iPadOS fires no composition
events for it — each jamo is a plain keydown while the IME rewrites the
syllable in place in the helper textarea — so xterm consumes the keydown, sends
the raw jamo from `_keyPress`, and drops the composed `insertText` because
`_inputEvent` admits a composed insert only when no key is down.

The jamo keydown is handed to the system by a new bypass rule, and the syllable
it builds is held in the renderer until the IME proves it final. The PTY sees
one write per syllable and nothing is ever sent then retracted, so raw-mode
TUIs never receive DEL bytes they need not read as "erase one cell" and SSH and
relay sessions pay no round trip for them. `한글깨짐` is four writes and zero
DELs.

Sitting upstream of `xterm-bypass-policy.ts` rather than inside xterm is what
makes this work for Shift-typed double consonants: Orca's own Shift rule
already hides `ㄲ ㄸ ㅃ ㅆ ㅉ` keydowns from xterm, so a fix living in
CompositionHelper never sees them and every syllable starting with one — 깨 꿈
딸 빵 쓰다 짜다 — stays broken. That placement call is dvpaa's, from stablyai#13346.

Composition sessions are left alone entirely, so Chinese pinyin on the same
device keeps working; that state is derived from the existing composition
tracker rather than latched, so a session that never ends cannot disable the
pane. The bypass claims jamo only — a Cyrillic or kana key would lose its
keydown, keypress and `input` alike and reach the PTY as nothing.

Co-authored-by: dvpaa <[email protected]>

* refactor(terminal): drop the dead session check from the iOS preedit input guard

`isCompositionOwnedInput(event) || options.isCompositionActive()` could never
take its second branch. The composition tracker's own `input` listener runs
first on the same element and clears its active flag for every input except
`insertCompositionText` — which is exactly the first disjunct. Verified by
construction: instrumented to throw on the combination, nothing in the renderer
suite (24k tests) reached it, and five deliberate attempts to build one, via a
resumed preedit and a post-compositionend insert, all failed to.

Reading composition ownership off the event alone also makes the decision
independent of listener registration order, which the previous comment at the
call site claimed to depend on. It does not: swapping the tracker and the
preedit controller leaves every test passing. The comment now states the one
coupling that is real — the controller stops propagation on `input` while a
syllable is held — without asserting a behavioral dependency that does not exist.

`isCompositionActive` remains the gate on opening a hold, where it is pinned.

* fix(terminal): settle iPad Hangul by diffing the field, not assuming it grows

The hold released a syllable only when the textarea tail grew past it and
still started with it. Korean batchim migration breaks that: a device
capture on iPadOS 26 shows `깨` + `ㅈ` rewritten to `깾` — a different
codepoint, not an extension — and only becoming `깨주` once the next vowel
decides where the `ㅈ` belongs. The prefix check failed there, the hold
stopped advancing, and `깨쥠` reached the PTY as one chunk on blur.

Locate the IME's edit with a prefix diff of the two field states instead.
Everything before where it began rewriting is settled: the batchim question
for those syllables is already answered. Still hold-and-commit, so no DEL
ever reaches the pty.

The capture is now the fixture, replayed both verbatim and as keystrokes.

* fix(terminal): keep the iPad Hangul hold open across the IME's erase rewrite

Backspace can decompose a held syllable as deleteContentBackward then a
replacing insertText, the same shape the IME uses to grow one. The hold
closed on the emptied half, so the replacement landed with nothing held:
typing 한, Backspace, ㄹ put a bare `ㄹ` on the wire and dropped 하.

The empty field now collapses the hold instead of closing it, and the
Backspace that finds nothing held is the one that reaches the PTY. An
`imeWrote` flag keeps an erased hold from resurrecting its opening jamo.

Also diff the field as NFC. Decomposed Hangul grows by appending jamo,
which the common-prefix diff reads as the previous syllable settling, so
an NFD source emitted one bare jamo per keystroke. The recorded device
trace is NFC, where normalization is a no-op.

* test(terminal): cover Japanese, Hanja and Greek on the iPad Hangul path

The coexistence suite proved pinyin and a short list of non-Hangul keys.
Widen it: a kana-to-kanji session, a Hanja lookup over a live preedit, a
digit that ends a held syllable as literal text, and Greek, halfwidth
kana and accented Latin among the keys the bypass must not claim.

---------

Co-authored-by: dvpaa <[email protected]>
(cherry picked from commit 0743394)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…enderer (stablyai#13345) (stablyai#15480)

* fix(terminal): compose iPadOS Hangul by holding the syllable in the renderer (stablyai#13345)

Korean typed on an iPad with a hardware keyboard reached the PTY as separate
jamo: `한글깨짐` arrived as `ㅎㅏㄴㄱㅡㄹ...`. iPadOS fires no composition
events for it — each jamo is a plain keydown while the IME rewrites the
syllable in place in the helper textarea — so xterm consumes the keydown, sends
the raw jamo from `_keyPress`, and drops the composed `insertText` because
`_inputEvent` admits a composed insert only when no key is down.

The jamo keydown is handed to the system by a new bypass rule, and the syllable
it builds is held in the renderer until the IME proves it final. The PTY sees
one write per syllable and nothing is ever sent then retracted, so raw-mode
TUIs never receive DEL bytes they need not read as "erase one cell" and SSH and
relay sessions pay no round trip for them. `한글깨짐` is four writes and zero
DELs.

Sitting upstream of `xterm-bypass-policy.ts` rather than inside xterm is what
makes this work for Shift-typed double consonants: Orca's own Shift rule
already hides `ㄲ ㄸ ㅃ ㅆ ㅉ` keydowns from xterm, so a fix living in
CompositionHelper never sees them and every syllable starting with one — 깨 꿈
딸 빵 쓰다 짜다 — stays broken. That placement call is dvpaa's, from stablyai#13346.

Composition sessions are left alone entirely, so Chinese pinyin on the same
device keeps working; that state is derived from the existing composition
tracker rather than latched, so a session that never ends cannot disable the
pane. The bypass claims jamo only — a Cyrillic or kana key would lose its
keydown, keypress and `input` alike and reach the PTY as nothing.

Co-authored-by: dvpaa <[email protected]>

* refactor(terminal): drop the dead session check from the iOS preedit input guard

`isCompositionOwnedInput(event) || options.isCompositionActive()` could never
take its second branch. The composition tracker's own `input` listener runs
first on the same element and clears its active flag for every input except
`insertCompositionText` — which is exactly the first disjunct. Verified by
construction: instrumented to throw on the combination, nothing in the renderer
suite (24k tests) reached it, and five deliberate attempts to build one, via a
resumed preedit and a post-compositionend insert, all failed to.

Reading composition ownership off the event alone also makes the decision
independent of listener registration order, which the previous comment at the
call site claimed to depend on. It does not: swapping the tracker and the
preedit controller leaves every test passing. The comment now states the one
coupling that is real — the controller stops propagation on `input` while a
syllable is held — without asserting a behavioral dependency that does not exist.

`isCompositionActive` remains the gate on opening a hold, where it is pinned.

* fix(terminal): settle iPad Hangul by diffing the field, not assuming it grows

The hold released a syllable only when the textarea tail grew past it and
still started with it. Korean batchim migration breaks that: a device
capture on iPadOS 26 shows `깨` + `ㅈ` rewritten to `깾` — a different
codepoint, not an extension — and only becoming `깨주` once the next vowel
decides where the `ㅈ` belongs. The prefix check failed there, the hold
stopped advancing, and `깨쥠` reached the PTY as one chunk on blur.

Locate the IME's edit with a prefix diff of the two field states instead.
Everything before where it began rewriting is settled: the batchim question
for those syllables is already answered. Still hold-and-commit, so no DEL
ever reaches the pty.

The capture is now the fixture, replayed both verbatim and as keystrokes.

* fix(terminal): keep the iPad Hangul hold open across the IME's erase rewrite

Backspace can decompose a held syllable as deleteContentBackward then a
replacing insertText, the same shape the IME uses to grow one. The hold
closed on the emptied half, so the replacement landed with nothing held:
typing 한, Backspace, ㄹ put a bare `ㄹ` on the wire and dropped 하.

The empty field now collapses the hold instead of closing it, and the
Backspace that finds nothing held is the one that reaches the PTY. An
`imeWrote` flag keeps an erased hold from resurrecting its opening jamo.

Also diff the field as NFC. Decomposed Hangul grows by appending jamo,
which the common-prefix diff reads as the previous syllable settling, so
an NFD source emitted one bare jamo per keystroke. The recorded device
trace is NFC, where normalization is a no-op.

* test(terminal): cover Japanese, Hanja and Greek on the iPad Hangul path

The coexistence suite proved pinyin and a short list of non-Hangul keys.
Widen it: a kana-to-kanji session, a Hanja lookup over a live preedit, a
digit that ends a held syllable as literal text, and Greek, halfwidth
kana and accented Latin among the keys the bypass must not claim.

---------

Co-authored-by: dvpaa <[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]: iPadOS hardware-keyboard Korean input reaches the terminal as uncomposed jamo in the web client

4 participants