Skip to content

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

Merged
nwparker merged 6 commits into
mainfrom
nwparker/ipad-hangul-renderer-preedit
Aug 27, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/ipad-hangul-renderer-preedit

Conversation

@nwparker

@nwparker nwparker commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1294 $\color{#cf222e}{\Huge{\mathbf{−}}}$​37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1257
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​806 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​796

Problem

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

Cause

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

Confirmed on the reporter's hardware rather than inferred: Chinese pinyin on the same device fires composition events normally, so this is specific to the Korean input mode.

Fix

Entirely in Orca's renderer. No xterm patch — config/patches/ is untouched.

  • xterm-bypass-policy.ts — shouldBypassXtermForIosTextEdit keeps xterm out of the way for jamo keys. Without it xterm preventDefaults the printable keydown and the IME never writes to the field at all. Deliberately narrowed to jamo only: xterm sets _keyDownSeen before consulting the custom handler, and _inputEvent admits a composed insertText only when no key is down — so a bypassed non-jamo key loses its keydown, its keypress and its input. A broader predicate makes Cyrillic, Greek and kana reach the PTY as nothing.
  • terminal-ios-hangul-preedit.ts — holds the syllable and commits only what a common-prefix diff proves settled. Never sends then retracts, so zero DEL bytes ever reach the PTY.
  • ios-web-platform.ts — userAgent.includes('Mac') && maxTouchPoints > 1. Every iOS user agent contains "Mac"; > 0 is too loose because a Mac with a touch peripheral reports 1.
  • An overlay drives .composition-view so the syllable visibly builds (하 → 한).

Why a diff and not a prefix test. The first version assumed the field only grows. It does not: after a batchim migration the IME reaches back and rewrites a syllable that looked finished — 깨 + ㅈ becomes 깾, then ㅜ turns it into 깨주 as the consonant migrates forward. A syllable is not final until the following syllable's vowel decides. Committing 깨 early would be wrong, so the diff commits only up to the point the IME's own edit has moved past.

Device verification

Recorded on a physical iPad (iPadOS 26, hardware Korean 2-set keyboard) through the real production module and xterm's actual helper textarea. The 34-event capture is committed as __fixtures__/ipados-hardware-2set-hangul-batchim-migration-trace.json and drives the suite.

sent: ['한', '글', '깨', '짐']
      U+D55C  U+AE00  U+AE68  U+C9D0     DEL bytes: 0

Per-syllable commits as the user types, with the final syllable correctly still held as an open preedit until space, Enter or blur.

Before the diff, the same device produced ['한','글','깨쥠'] — everything after the first batchim migration accumulated and arrived in one chunk on blur. Reverting to the growth assumption fails 27 tests, emitting that string verbatim.

Verification

  • 26 mutations, 26 killed. Two rounds: one survivor (dispose()'s overlay cleanup) got a test; a second survivor appeared because of a fix (collapsing instead of closing made the compose-deletion skip unobservable in emitted data) and got a test asserting the overlay mid-rewrite.
  • Coexistence proved by running, not reading: Pinyin (single, consecutive, interleaved with Hangul both orders, and after a composition that never ended), Japanese kana-to-kanji, Hanja (both over a live composition and after a held syllable), and Cyrillic / Greek / hiragana / halfwidth katakana / accented Latin / € all intact.
  • Desktop inert at maxTouchPoints 0 and 1, plus Windows and Linux user agents, driving a real Terminal.
  • 68 targeted tests; 26,750 pass across src/renderer. tsc, oxlint, oxfmt, max-lines ratchet all clean. No dependency or lockfile change.

Not verified — read before merging

  • Nothing here executes on iOS or iPadOS in CI. The unit gate is ubuntu + windows-2022; the IME e2e workflow is ubuntu with ibus-hangul, a different engine. The 68 tests run under happy-dom. The only real-device evidence is the recorded trace above.
  • Overlay positioning is untested. happy-dom gives .xterm-screen a zero-sized rect, so the geometry branch short-circuits; only text content and the active class are ever exercised. Worth a device pass before release.
  • Two fixes are defensive, from constructed inputs rather than the recording, and are labelled as such: Backspace arriving as delete-then-insert (the recording never presses Backspace, though it is the same shape the IME provably uses when a syllable grows), and NFD normalization (the recorded field is NFC throughout — this guards the decomposed-Hangul work in flight elsewhere, where an appending field would otherwise put one bare jamo on the wire per keystroke).

Supersedes #15456, which patched the vendored xterm and — being downstream of the bypass policy — never fixed Shift-typed jamo, so every syllable starting with a double consonant broke.

Co-authored-by: dvpaa — the decision to fix this above the terminal rather than inside it is theirs, from #13346.

…enderer (#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]>
@coderabbitai

coderabbitai Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 2 minutes.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 04464974-0872-4882-b156-f1de49fee034

📥 Commits

Reviewing files that changed from the base of the PR and between 7d905a4 and 0e67511.

📒 Files selected for processing (1)
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-coexistence.test.ts

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: f05f35e8-24fd-4da8-aaac-7b01b975814b

📥 Commits

Reviewing files that changed from the base of the PR and between 1485aa4 and 7d905a4.

📒 Files selected for processing (14)
  • src/renderer/src/components/terminal-pane/__fixtures__/ipados-hardware-2set-hangul-batchim-migration-trace.json
  • src/renderer/src/components/terminal-pane/hangul-jamo-key.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-coexistence.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-device-trace.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-overlay.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.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
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/renderer/src/lib/ios-web-platform.test.ts
  • src/renderer/src/lib/ios-web-platform.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-coexistence.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy-ios.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-overlay.ts
  • src/renderer/src/components/terminal-pane/hangul-jamo-key.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts

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


📝 Walkthrough

Walkthrough

Adds iOS WebKit and iPadOS desktop-mode detection. Adds Hangul jamo event bypassing for xterm. Adds Hangul preedit tracking, commit, cancellation, deletion handling, and overlay rendering. Wires the feature into terminal lifecycle management. Adds fixtures and tests for Hangul composition, Chinese pinyin coexistence, device traces, platform gating, and other scripts. Removes the previous touch-based iOS helper and its tests.

Merge Risk: 🔵 Low · up to 7d905

The PR adds narrowly gated iPadOS Hangul preedit handling and is mergeable with explicit owner awareness: tearing down a pane while a syllable is still held may discard typed input, and one test is coupled to source text and process.cwd(), so unrelated refactors or configuration changes could break the suite.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 12 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides detailed problem, cause, fix, linked issue, testing, and device-verification information. However, it omits several required template sections, including ELI5, Visual Proof or… Update the description to follow the repository template. Add ELI5, What Changed, Why, Visual Proof or an explicit N/A explanation, Testing checklist status, AI Disclosure if applicable, Review, Notes, and Checklist sections. Resolve the co…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: composing iPadOS Hangul input in the renderer.
Full details: Docstring Coverage

Explanation

Docstring coverage is 55.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 12 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description provides detailed problem, cause, fix, linked issue, testing, and device-verification information. However, it omits several required template sections, including ELI5, Visual Proof or an explicit N/A explanation, checklist items, and review notes. It also conflicts with the provided PR objectives, which describe workspace layout duplication rather than iPadOS Hangul input.

Resolution

Update the description to follow the repository template. Add ELI5, What Changed, Why, Visual Proof or an explicit N/A explanation, Testing checklist status, AI Disclosure if applicable, Review, Notes, and Checklist sections. Resolve the conflict with the PR objectives by aligning the objectives with the iPadOS Hangul changes or correcting the changeset and description.

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-overlay.ts (1)

49-51: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer theme tokens over raw hex fallbacks.

#000 and #FFF are hardcoded colors. The renderer style guide requires colors from the tokens in src/renderer/src/assets/main.css. The primary values come from terminal.options.theme, so the fallback is rarely used, but a token keeps the overlay consistent with the pane when the theme is unset.

As per path instructions: "All renderer UI work must follow docs/STYLEGUIDE.md, use tokens from src/renderer/src/assets/main.css... do not invent documented colors, font sizes, or shadow tiers."

Source: Path instructions

src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.ts (1)

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

Global navigator overrides have no paired restore. pretendIosWeb replaces navigator.userAgent and navigator.maxTouchPoints and leaves the restore to each caller. Two suites implement it by hand and one does not, so the override can outlive its file.

  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.ts#L32-L51: save the original property descriptors inside pretendIosWeb and restore them in disposeOpenTerminals; also track and remove the appended containers there.
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-device-trace.test.ts#L51-L62: once the fixture restores the descriptors, drop the need for a local restore; until then, save and restore navigator.userAgent and navigator.maxTouchPoints as the other two suites do.
src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-coexistence.test.ts (1)

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

Replace the source-text assertion with a behavior assertion.

This test reads use-terminal-pane-lifecycle.ts as text and matches regexes against it. Three problems follow:

  • A harmless edit breaks it. Renaming isIosWeb, wrapping the ternary across lines, or extracting the install into a helper all fail the test without changing behavior.
  • process.cwd() must equal the repository root. If the renderer ever gets its own Vitest root, resolve produces a wrong path and the test fails on an unrelated config change.
  • The property it checks — a single platform gate — is already covered behaviorally by the desktop-inertness tests above (lines 130-159), which prove the controller does not run off iOS web.

Remove this test, or assert the same property through the rig instead of the file contents.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d6a9594a-3d08-43de-8074-769d68c0ec59

📥 Commits

Reviewing files that changed from the base of the PR and between 73f7767 and 85054f0.

📒 Files selected for processing (13)
  • src/renderer/src/components/terminal-pane/hangul-jamo-key.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-coexistence.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-device-trace.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-fixture.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-overlay.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.test.ts
  • src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.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
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts

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

Comment on lines +244 to +253
return {
heldText: () => preedit?.heldText ?? '',
dispose: () => {
root.removeEventListener('keydown', handleKeyDown, true)
root.removeEventListener('input', handleInput, true)
root.removeEventListener('compositionstart', handleCompositionStart, true)
root.removeEventListener('blur', handleBlur, true)
close()
}
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check whether the preedit dispose can run while a hold is open, and in what order relative to terminal disposal.
set -euo pipefail

fd -t f 'use-terminal-pane-lifecycle.ts' -x rg -n -C 6 'imeCompositionDisposablesRef|iosHangulPreedit|manager.destroy\(\)|terminal.dispose\(\)' {}
fd -t f 'pane-manager*.ts' -x rg -n -C 6 'dispose\(\)|destroy\(\)|blur\(' {}

Repository: stablyai/orca

Length of output: 5901


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- preedit implementation ---'
fd -t f 'terminal-ios-hangul-preedit.ts' -x cat -n {} | sed -n '1,290p'

printf '%s\n' '--- lifecycle cleanup and pane disposal ---'
fd -t f 'use-terminal-pane-lifecycle.ts' -x sed -n '1330,1410p' {}
fd -t f 'use-terminal-pane-lifecycle.ts' -x sed -n '1870,1945p' {}

printf '%s\n' '--- PaneManager.destroy and pane disposal ---'
fd -t f 'pane-manager*.ts' -x sed -n '320,390p' {}
fd -t f 'pane-manager*.ts' -x rg -n -C 12 'dispose\(\)|destroy\(\)|terminal\.dispose|panes\.clear' {}

printf '%s\n' '--- all preedit disposal call sites ---'
rg -n -C 5 'installTerminalIosHangulPreedit|iosHangulPreedit|terminal-ios-hangul-preedit|imeCompositionDisposablesRef' .

Repository: stablyai/orca

Length of output: 42012


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- pane disposable definition and close callback context ---'
fd -t f 'use-terminal-pane-lifecycle.ts' -x rg -n -C 18 'const disposable|disposable =|onPaneClosed|disposePane' {}

printf '%s\n' '--- disposePane implementation ---'
rg -n -C 20 'function disposePane|const disposePane|export .*disposePane' src/renderer/src

printf '%s\n' '--- focused source invariant check ---'
python3 - <<'PY'
from pathlib import Path

preedit = Path('src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.ts').read_text()
lifecycle = Path('src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts').read_text()

assert 'const close = (): void' in preedit
close_start = preedit.index('const close = (): void')
close_end = preedit.index('const commit = (): void', close_start)
close_body = preedit[close_start:close_end]
assert 'preedit = null' in close_body
assert 'sendInput' not in close_body

dispose_start = preedit.index('dispose: () => {')
dispose_end = preedit.index('\n    }\n  }', dispose_start)
dispose_body = preedit[dispose_start:dispose_end]
assert 'close()' in dispose_body
assert 'commit()' not in dispose_body

pane_close = lifecycle.index('const imeCompositionDisposable = imeCompositionDisposablesRef.current.get(paneId)')
pane_close_end = lifecycle.index('const imeNativeTextForwarderDisposable', pane_close)
pane_close_body = lifecycle[pane_close:pane_close_end]
assert pane_close_body.index('imeCompositionDisposable.dispose()') < pane_close_body.index('disposable.dispose()') if 'disposable.dispose()' in pane_close_body else True

unmount = lifecycle.index('for (const disposable of imeCompositionDisposables.values())')
manager_destroy = lifecycle.index('manager.destroy()', unmount)
assert unmount < manager_destroy

print('dispose() clears the held preedit without sending it.')
print('Unmount cleanup disposes IME handlers before manager.destroy().')
print('The remaining question is whether pane-close disposable.dispose() destroys the terminal; inspect its implementation.')
PY

Repository: stablyai/orca

Length of output: 14766


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- pane disposable definition and close callback context ---'
fd -t f 'use-terminal-pane-lifecycle.ts' -x rg -n -C 18 'const disposable|disposable =|onPaneClosed|disposePane' {}

printf '%s\n' '--- disposePane implementation ---'
rg -n -C 20 'function disposePane|const disposePane|export .*disposePane' src/renderer/src

printf '%s\n' '--- focused source invariant check ---'
python3 - <<'PY'
from pathlib import Path

preedit = Path('src/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit.ts').read_text()
lifecycle = Path('src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts').read_text()

close_start = preedit.index('const close = (): void')
close_end = preedit.index('const commit = (): void', close_start)
assert 'preedit = null' in preedit[close_start:close_end]
assert 'sendInput' not in preedit[close_start:close_end]

dispose_start = preedit.index('dispose: () => {')
dispose_end = preedit.index('\n    }\n  }', dispose_start)
dispose_body = preedit[dispose_start:dispose_end]
assert 'close()' in dispose_body
assert 'commit()' not in dispose_body

unmount = lifecycle.index('for (const disposable of imeCompositionDisposables.values())')
manager_destroy = lifecycle.index('manager.destroy()', unmount)
assert unmount < manager_destroy

print('dispose() clears the held preedit without sending it.')
print('Unmount cleanup disposes IME handlers before manager.destroy().')
PY

Repository: stablyai/orca

Length of output: 14649


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- closePane call and implementation ---'
rg -n -C 30 'closePane\(' src/renderer/src/lib/pane-manager src/renderer/src/components/terminal-pane

printf '%s\n' '--- complete disposePane body ---'
fd -t f 'pane-lifecycle.ts' -x sed -n '169,260p' {}

printf '%s\n' '--- pane-manager callback ordering ---'
rg -n -C 25 'onPaneClosed|disposePane\(' src/renderer/src/lib/pane-manager

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- delegated close implementation ---'
rg -n -C 35 'closePaneOnManager|function closePane|const closePane' src/renderer/src/lib

printf '%s\n' '--- terminal disposal in pane lifecycle ---'
fd -t f 'pane-lifecycle.ts' -x rg -n -C 12 'terminal\.dispose|onPaneClosed|panes\.delete|return' {}

printf '%s\n' '--- callback ordering assertions ---'
python3 - <<'PY'
from pathlib import Path

root = Path('src/renderer/src/lib')
matches = []
for path in root.rglob('*.ts'):
    text = path.read_text()
    if 'closePaneOnManager' in text or 'function closePane' in text or 'const closePane' in text:
        matches.append(path)

for path in matches:
    print(path)
    for i, line in enumerate(path.read_text().splitlines(), 1):
        if 'closePaneOnManager' in line or 'function closePane' in line or 'const closePane' in line:
            print(f'{i}: {line.strip()}')
PY

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- delegated close implementation ---'
rg -n -C 35 'closePaneOnManager|function closePane|const closePane' src/renderer/src/lib

printf '%s\n' '--- terminal disposal in pane lifecycle ---'
fd -t f 'pane-lifecycle.ts' -x rg -n -C 12 'terminal\.dispose|onPaneClosed|panes\.delete|return' {}

printf '%s\n' '--- callback ordering assertions ---'
python3 - <<'PY'
from pathlib import Path

root = Path('src/renderer/src/lib')
for path in root.rglob('*.ts'):
    text = path.read_text()
    if 'closePaneOnManager' in text or 'function closePane' in text or 'const closePane' in text:
        print(path)
        for i, line in enumerate(text.splitlines(), 1):
            if 'closePaneOnManager' in line or 'function closePane' in line or 'const closePane' in line:
                print(f'{i}: {line.strip()}')
PY

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

files=$(rg -l 'closeManagedPane' src/renderer/src)
printf '%s\n' '--- files defining or calling closeManagedPane ---'
printf '%s\n' "$files"

while IFS= read -r file; do
  printf '\n--- %s ---\n' "$file"
  rg -n -C 25 'closeManagedPane|onPaneClosed|disposePane|terminal\.dispose' "$file"
done <<< "$files"

Repository: stablyai/orca

Length of output: 8262


Commit the held preedit before pane teardown.

dispose() currently drops a held syllable without calling sendInput(). Make it commit pending text, and invoke it before closeManagedPane() disposes the terminal; onPaneClosed runs too late.

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

Copy link
Copy Markdown
Contributor Author

Device test on real hardware — works, with one bug found

Tested on a physical iPad (iPadOS 26, hardware Korean 2-set keyboard) against the real production module through xterm's actual helper textarea. Two runs, byte-identical results.

What works, confirmed on device:

  • iPad detection. maxTouchPoints: 5, UA Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ... Version/26. That UA contains Macintosh and no iOS marker, which is exactly why a user-agent test alone cannot work here and maxTouchPoints > 1 is the right separator.
  • The bypass. Without it xterm preventDefaults the printable keydown and the IME never writes to the field at all — an earlier run of this harness omitted it and produced 13 keydowns with zero input events and an empty textarea.
  • Composition. Typing gksrmfRownla produced 한글깨쥠, which is the correct composition for those keys.
  • Zero DEL bytes, as designed.

The bug: syllables stop committing after a batchim migration.

sent: ['한','글','깨쥠'] — correct text, but 깨쥠 arrived as one chunk on blur instead of committing per syllable. From the trace:

keydown ㅈ                     value="한글깨"
input  deleteContentBackward   value="한글"      <- deletes the finished 깨
input  insertText data="깾"    value="한글깾"     <- reinserts it as 깾
keydown ㅜ                     value="한글깾"
input  deleteContentBackward   value="한글"
input  insertText data="깨주"   value="한글깨주"   <- ㅈ migrates forward

The IME reaches back and rewrites a syllable that looked finished. ㅈ first attaches to 깨 as a final consonant, then migrates forward to become the next syllable's initial once ㅜ arrives. A syllable is not final until the following syllable's vowel decides, so this is ordinary Korean typing rather than an edge case.

terminal-ios-hangul-preedit.ts syncs with a prefix assumption — commit when the tail grew past heldText and starts with it. 깾 does not start with 깨 (different codepoints), so the check fails, the hold stops advancing, and everything accumulates until an explicit commit or blur.

User-visible effect: correct text delivered late. In a terminal, nothing reaches the shell after the first batchim migration until space, Enter, or focus loss.

Holding is still the right behaviour — committing 깨 on ㅈ would be wrong, because ㅈ might belong to 깨 as 깾. The fix is to replace the prefix assumption with a common prefix/suffix diff so non-monotonic rewrites are handled by construction. Architecture is unchanged: still hold-and-commit, still zero DELs, still no xterm patch.

The 34-event recording is being added as a replay fixture. The previous round of this work passed on a hand-built shape the device never produces, which is how the Shift-jamo (깨) gap shipped — so the test will pin the real recording rather than a reconstruction.

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

Copy link
Copy Markdown
Contributor Author

Device-verified on a physical iPad — passes

Same hardware and harness as the failure recorded above (iPadOS 26, hardware Korean 2-set keyboard, real production module through xterm's actual helper textarea).

sent: ['한', '글', '깨', '짐']
      U+D55C  U+AE00  U+AE68  U+C9D0
DEL bytes: 0

All four syllables, correct codepoints, committed one at a time as the user types. Compare the pre-fix run on the same device: ['한','글','깨쥠'], where everything after the first batchim migration accumulated and arrived in one chunk on blur.

Observed behaviour is that three syllables appear while typing and the fourth appears on focus loss. That is correct — the final syllable is legitimately still an open preedit, and it commits on space, Enter, or blur like any other IME. In a terminal the user never sees it held, because the command ends with one of those.

Both device-found defects are now fixed and pinned to the recording:

  • Shift-typed jamo (ㄲ ㄸ ㅃ ㅆ ㅉ) reaching the field at all, which the earlier vendored-xterm approach could not do — its gksrmf test was all-unshifted, which is why the gap stayed hidden.
  • Batchim migration, where the IME reaches back and rewrites a syllable that looked finished.

Reverting the diff to the previous growth assumption fails 4 tests, emitting ['한','글','깨쥠'] — the device bug verbatim.

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

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.
@nwparker
nwparker merged commit 0743394 into main Aug 27, 2026
51 checks passed
@nwparker
nwparker deleted the nwparker/ipad-hangul-renderer-preedit branch August 27, 2026 23:06
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

1 participant