Skip to content

fix(terminal): compose Hangul from a keydown-only IME on iPadOS (#13345) - #15456

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/ipad-hangul-keydown-preedit
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/ipad-hangul-keydown-preedit

Conversation

@nwparker

@nwparker nwparker commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​420 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​420
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​515 $\color{#cf222e}{\Huge{\mathbf{−}}}$​91 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​424

Fixes #13345 — Korean typed on an iPad reached the terminal as separate jamo instead of composed syllables.

Root cause

iPadOS Korean fires zero composition events. No compositionstart, no compositionupdate, no compositionend — just plain keydowns, while the IME rewrites the helper textarea in place (a deleteContentBackward followed by a replacing insertText). xterm's CompositionHelper is built entirely around composition events, so it never saw a composition and forwarded each jamo as it arrived.

Confirmed on the reporter's hardware, not inferred: Chinese pinyin on the same device does fire composition events normally. It is specific to the Korean input mode.

Fix

CompositionHelper now holds Hangul jamo keydowns as a preedit and syncs from the textarea, in the patched xterm source.

Two device-measured details that shaped it:

  • isTouchIOS() uses maxTouchPoints > 1, not > 0. Every iOS user agent contains "Mac" (Macintosh in desktop mode, like Mac OS X in mobile), so the UA alone cannot separate iPad from Mac. > 0 is also wrong — a Mac with a touch peripheral reports 1.
  • The sync is driven from input(), not a timer. The first two attempts failed on device. _defer is setTimeout(0), and iPadOS delivers input later than a macrotask, so any timer-based read raced the IME's write and lost. xterm calls input() for insertText alone, which is exactly when the IME has finished writing the field. The timer now never sends and never ends the hold; stranded keys resolve on the next keydown.

Verification

Device-confirmed by the reporter on the final build: typing gksrmf sends 한 and correctly holds 글 as a still-open preedit — committed text out, live syllable retained, which is the desired IME behavior rather than a partial send.

420 lines of unit coverage in terminal-ime-xterm-ipad-hangul-keydown.test.ts.

Note on the patch files

Regenerated through config/scripts/regenerate-xterm-patches.mjs, never hand-edited — the xterm patch sync CI gate enforces that the bundle matches the reviewable source patch. Review config/patches/xterm-src/@[email protected]; the binary bundle is generated output.

Korean typed on an iPad with a hardware keyboard reaches the terminal as
loose jamo: 한글 arrives as ㅎㅏㄴㄱㅡㄹ. The same keystrokes compose
correctly in an ordinary text field in the same browser on the same
device, so it is not a platform limit.

iPadOS Hangul fires no composition events at all. Each jamo is a plain
keydown, and the IME rewrites the syllable in place in the helper
textarea. The terminal sends the raw jamo from the key path, and the
composed syllable that follows by input event is then rejected because a
key is down for every one of them.

The IME is real, it just does not announce itself, so mirror it: hold
the syllable as a preedit and let the textarea say when it is final. The
commit signal is the shape of the rewrite, which the recorded trace
already carries - while a syllable is still forming the IME replaces it,
and once it is final the next jamo appends. A tail that grew past what
was held is therefore the only signal needed.

    ㅎ -> 하 -> 한   held, nothing sent
    한ㄱ             appended, so 한 commits
    한그 -> 한글     held
    Enter            글 commits, then the newline

One commit per syllable, no intermediate text on the wire, and no erase
characters - which matters because a full screen application cannot be
assumed to accept them mid-input.

Scoped to touch iOS by user agent and touch points, since every iOS user
agent reports a Mac. Windows and Linux cannot reach the code, desktop
macOS is excluded by touch points, and non-Hangul keys are excluded by
the jamo range. Disabled under screen reader mode, which drives the
textarea itself and would make the diff unreliable; Korean stays broken
there rather than risking input vanishing.

Rendering reuses the existing preedit overlay, so the held syllable
inherits the underline, the row tail and the cursor anchoring the
composition path already has.

Backspace and Escape are handled but unobserved on the device: a
shrinking tail re-renders, an emptied tail ends the hold, and neither
sends a byte, since nothing was sent to undo.

Refs #13345
The first pass held the syllable correctly but still sent every jamo
raw. A device trace showed why: the read that re-derives the preedit is
armed on a timer, and iPadOS delivers the matching input event later
than a macrotask. The timer therefore always fired first, saw a field
the IME had not written yet, concluded the key produced nothing, and
sent it.

Adding a second turn did not help - two timers still beat the write, and
a timing constant large enough to win would be a guess.

So the timer no longer decides anything. It updates the preedit when
there is something to read, and returns otherwise. It does not send, and
it does not end the hold either: ending it was equally wrong, because a
write arriving afterwards would find no preedit and fall through to the
raw key path.

The question the timer was guessing at - did this key produce any text -
is now answered where it is a fact rather than a race. The input event
drives the read, since xterm delivers it for insertText alone, which is
exactly when the IME has finished writing. A key that genuinely composed
nothing is settled on the next keydown.

Refs #13345
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The xterm patch adds transaction-aware composition handling and public IME lifecycle methods. It supports touch-iOS Hangul preedit editing, deferred keypress and textarea input reconciliation, cancellation, blur, disposal, and composition overlay rendering. Core browser integration forwards accepted composition events and suppresses duplicate input. SortedList.delete retries deletion after flushing pending mutations. A regression suite covers Hangul composition, editing, lifecycle events, compatibility paths, and delayed IME writes.

Merge Risk: 🟡 Moderate · up to e0995

The change should correctly support Korean Hangul composition on iPadOS, but the current patch has an undeclared variable in the TypeScript source that can prevent compilation. Fix that issue before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the root cause, fix, linked issue, device verification, and test coverage, but omits most required template sections and visual proof. Add the required template sections, include visual proof or an explicit N/A reason, and complete testing, review, checklist, and AI disclosure fields.
Out of Scope Changes check ⚠️ Warning The patch also changes SortedList.delete retry behavior, which is not tied to the linked iPadOS Hangul objectives and is not explained in the description. Remove the unrelated SortedList.delete change or document the concrete dependency that makes it necessary for the iPadOS Hangul fix.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: composing Hangul from keydown-only input on iPadOS.
Linked Issues check ✅ Passed The patch and regression suite address iPadOS detection, keydown-only Hangul composition, textarea synchronization, preedit behavior, and the linked issue’s coverage objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
config/patches/xterm-src/@[email protected] (1)

1247-1267: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Declare i inside _deleteAtKey
_deleteAtKey uses i without a local declaration. Add let i = this._search(key);; otherwise the TypeScript source does not compile.

🧹 Nitpick comments (2)
config/patches/xterm-src/@[email protected] (1)

129-131: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the unused settled field from IHangulKeydownPreedit.

No code reads or writes settled, and its comment describes behavior not implemented by the final state. Remove both the field and its comment.

src/renderer/src/components/terminal-pane/terminal-ime-xterm-ipad-hangul-keydown.test.ts (1)

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

Use dispatchInput for the delayed input event. [email protected] preserves data and inputType from InputEventInit, but the inline event leaves composed false. dispatchInput sets composed: true and exercises xterm’s composed-input path.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50766bf3-e9ec-4bcd-872f-5fcc67f551df

📥 Commits

Reviewing files that changed from the base of the PR and between 41c4d8e and e099588.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)

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

@nwparker

Copy link
Copy Markdown
Contributor Author

Holding this — the vendored-xterm-patch approach is disfavoured on maintainability grounds.

That patch has to be regenerated through config/scripts/regenerate-xterm-patches.mjs and re-applied on every xterm bump, which is real recurring cost for a fix that may be achievable in Orca's own renderer layer.

#13346 (community PR by @dvpaa) fixes the same bug by mirroring iOS field edits to the PTY, touching no xterm patch. It is now the front-runner and is under review. If it is correct — or close enough to fix — this PR should be closed in its favour.

Keeping this open only until that review lands, since the diagnosis and the device-measured constraints here are worth preserving either way:

  • iPadOS Korean fires zero composition events — plain keydowns while the IME rewrites the helper textarea in place (deleteContentBackward then a replacing insertText).
  • Chinese pinyin on the same device fires composition events normally, so any fix must not disturb it.
  • _defer is setTimeout(0), and iPadOS delivers input later than a macrotask — any timer-based read of the textarea loses that race. This PR was rewritten twice before that was understood.
  • Every iOS user agent contains "Mac" (Macintosh in desktop mode, like Mac OS X in mobile), so a UA check alone cannot separate iPad from Mac. maxTouchPoints > 1 is the separator; > 0 is too loose because a Mac with a touch peripheral reports 1.

@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded by #15480, which fixes the same bug without patching the vendored xterm.

Two reasons this approach was abandoned rather than merged:

It never fixed the reported case. This sits downstream of Orca's own bypass policy, which claims Shift-typed jamo (ㄲ ㄸ ㅃ ㅆ ㅉ), so xterm never sees those keydowns. Every syllable starting with a double consonant breaks — including 한글깨짐, the string from #13345. The device test that passed here was gksrmf, all unshifted, which is exactly why the gap stayed hidden.

The 7MB vendored patch has to be regenerated on every xterm bump, and the renderer layer turned out to be able to do the job — verified point by point: keydown suppression via attachCustomKeyEventHandler, cursor position via the public buffer API, screen-reader mode via public options, and a capture-phase input listener that fires earlier than xterm's own handler, so there is no timing advantage to being inside it.

#15480 is now confirmed working on a physical iPad against a recorded device trace.

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

1 participant