Skip to content

fix(terminal): clear the preedit overlay when an IME cancels a composition - #14758

Merged
nwparker merged 1 commit into
mainfrom
nwparker/cangjie-cancelled-preedit
Aug 16, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/cangjie-cancelled-preedit

Conversation

@nwparker

@nwparker nwparker commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81 $\color{#cf222e}{\Huge{\mathbf{−}}}$​49 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32

ELI5

When Cangjie composition was cancelled before committing a character, xterm could leave the last preedit glyph painted over the terminal. The overlay now follows whether marked text actually exists, so cancellation clears and hides it without sending text to the shell.

What Changed

  • Updated the vendored xterm CompositionHelper production patch in config/patches/@[email protected].
  • Empty compositionupdate data now removes the overlay's active class.
  • A deferred state check catches cancellation paths that emit only a deleting input event and no composition event.
  • Cancelling clears the overlay text so a stale glyph cannot reappear.
  • Added focused regression coverage for empty-update cancellation, input-only cancellation, and shortening a multi-character preedit.
  • Updated the lockfile patch hash; dependency versions are unchanged.

Why

The fix is state-driven rather than key-driven. Backspace is not special-cased: after the IME settles, an empty marked-text region means the composition is gone. This covers both event sequences that can leave stale UI while preserving normal edits that merely shorten a composition.

The existing cancellation test checked only that onData emitted nothing. It could pass while the stale overlay remained visible, so the new test asserts the rendered overlay state and text directly.

Linked Issue

Fixes #11951

#14902 is adjacent IME work but not the same defect: it concerns Cursor Agent candidate-window positioning. It should remain separate.

Visual Proof

Exact head 99351010135f078e82980840672bd3762b340dbe, rendered in Orca on an M4 Air running macOS 26.5.2:

Cangjie preedit visible Composition cancelled
Cangjie preedit visible Composition cancelled

The before state rendered 尸 in .composition-view.active. Clearing the composition removed active, emptied the glyph content, hid the overlay, and left the PTY cursor unchanged with zero new lines.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • M4 Air / macOS 26.5.2: exact-head dev app attached through Electron CDP; visible preedit and cancelled state captured at 1710×1073.

  • M4 Air backing state: target PTY stayed at cursor 706 with zero new lines before/after cancellation.

  • Focused IME suite: 18 files / 54 tests passed.

  • pnpm typecheck passed.

  • pnpm lint passed.

  • Focused oxlint and formatting passed.

  • PR CI covers the full cross-platform suite and packaging.

AI Disclosure

Review

Self-reviewed the xterm patch and regression coverage for correctness, cleanup, stale overlay state, emitted terminal data, and the non-cancelling shortening case. CodeRabbit's latest review generated no actionable comments.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • The M4 Air was at loginwindow, so a physical/System Events Cangjie keystroke could not target the app. The built-in Cangjie source was present and selected, while Chromium's native Input.imeSetComposition command drove the real terminal text client. This proves rendered cancellation and PTY isolation on macOS, but not the reporter's exact hardware event trace.
  • Sourcemap hunks in the vendored patch remain stale for the changed methods. Rebuilding rewrites every mangled name and would make the patch substantially less reviewable; this affects DevTools mapping, not runtime behavior.
  • A separate upstream path where Chromium reports a composing key as literal Backspace/keyCode 8 can finalize text into the PTY. It is pre-existing, was unchanged here, and needs its own evidence and issue before broadening this fix.
  • The change is renderer-local and does not alter remote wire data, host execution, filesystem paths, shortcuts, or Git/provider behavior. SSH and folder workspaces use the same terminal renderer path.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author

  • X / Twitter: N/A

@coderabbitai

coderabbitai Bot commented Aug 15, 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: 8e9300aa-f3d5-44a3-b7ca-42c3a4656bc0

📥 Commits

Reviewing files that changed from the base of the PR and between f4319ba and 9935101.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • config/patches/@[email protected]
  • src/renderer/src/components/terminal-pane/terminal-ime-xterm-cancelled-preedit-visibility.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/terminal-pane/terminal-ime-xterm-cancelled-preedit-visibility.test.ts

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


📝 Walkthrough

Walkthrough

Added a Vitest/happy-dom regression test for xterm IME preedit visibility. The test simulates empty-update cancellation, input-only cancellation, and deletion from a multi-character preedit. It checks overlay visibility, displayed text, covered cells, and emitted data. Test setup configures canvas measurements, waits for deferred updates, disposes terminals, restores mocks, and clears the document.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The test covers the linked bug, but the review summary provides no production-file evidence for the claimed CompositionHelper fix. Provide the production diffs or file summaries that implement the preedit cancellation fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The reviewable change adds focused regression coverage for the linked Cangjie IME overlay bug and shows no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes the primary fix for stale preedit overlays after IME composition cancellation.
Description check ✅ Passed The description follows the required template and covers the change, rationale, issue, visual proof, testing, review, impact, and checklist.
✨ 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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-ime-xterm-cancelled-preedit-visibility.test.ts (1)

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

Reduce the file-level comment.

The comment documents the full event flow and test implementation. The fixtures and test names already provide that detail. Keep only the issue reference and the required visible behavior.

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

Proposed reduction
-/**
- * Cancelling a composition must also take the preedit overlay off the screen.
- *
- * Reported for macOS Cangjie (`#11951`): compose until the preedit shows 尸, press Backspace before
- * committing a candidate, and 尸 stays painted over the terminal. Backspacing the last radical
- * makes the IME's marked text empty, which Chromium reports either as a `compositionupdate` with
- * empty data or — when the composition never produced a candidate — as nothing more than the
- * deleting `input` event. Neither path reaches `compositionend`, and xterm only ever dropped the
- * overlay's `active` class there, so the box kept whatever glyph it was last given.
- *
- * The assertions are on what the user sees: the `active` class CSS keys `display: block` off, the
- * text inside the box, and the cells it therefore covers. `onData` is asserted too, but only as a
- * guard — it is already empty on the broken build, which is why the existing cancellation coverage
- * in `terminal-ime-xterm-composition-cancel.test.ts` cannot catch this.
- *
- * happy-dom performs no layout, so the cell size is supplied and the covered footprint is derived
- * from the overlay's own display state rather than measured.
- */
+/** Covers `#11951`: cancelling Cangjie preedit must clear and hide the composition overlay. */

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d89a6a08-4d94-42be-8664-ed09066daca6

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7f442 and 45d58d5.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • config/patches/@[email protected]
  • src/renderer/src/components/terminal-pane/terminal-ime-xterm-cancelled-preedit-visibility.test.ts

…ition

Backspacing over the last radical of a Cangjie composition empties the IME's
marked text without reaching compositionend, and the vendored xterm
CompositionHelper only dropped the overlay's `active` class there. The box
stayed painted with whatever glyph it last held (#11951).

Clear on the state rather than on the key, as native terminals do: an empty
`compositionupdate` now hides the overlay instead of only ever showing it, and
a key the IME swallows re-derives the preedit from the textarea once it settles
so a composition emptied with no composition event at all is cancelled too.
@nwparker
nwparker force-pushed the nwparker/cangjie-cancelled-preedit branch from 45d58d5 to 9935101 Compare August 16, 2026 22:34
@coderabbitai

coderabbitai Bot commented Aug 16, 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.

@OrcaWin

OrcaWin commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Attachments

M4 Air Cangjie preedit cancellation (before / after)

pr14758-cangjie-preedit.png pr14758-cangjie-cancelled.png
pr14758-cangjie-preedit.png pr14758-cangjie-cancelled.png

@nwparker
nwparker merged commit 17ef6cc into main Aug 16, 2026
45 checks passed
@nwparker
nwparker deleted the nwparker/cangjie-cancelled-preedit branch August 16, 2026 22:53
AmethystLiang pushed a commit that referenced this pull request Aug 17, 2026
…ition (#14758)

Backspacing over the last radical of a Cangjie composition empties the IME's
marked text without reaching compositionend, and the vendored xterm
CompositionHelper only dropped the overlay's `active` class there. The box
stayed painted with whatever glyph it last held (#11951).

Clear on the state rather than on the key, as native terminals do: an empty
`compositionupdate` now hides the overlay instead of only ever showing it, and
a key the IME swallows re-derives the preedit from the textarea once it settles
so a composition emptied with no composition event at all is cancelled too.
nwparker added a commit that referenced this pull request Aug 17, 2026
Second readiness pass, checking each of the first pass's ten fixes rather than
taking them on trust. Nine held. This is the one that did not, plus three
fail-open shapes in the site-config scanner that a live OpenSSH disproved.

P1 — the store. loadTrustedHostKeys returns [] for ANY read failure, and
trustHostKey then wrote [...that empty list, newRecord]: one transient EMFILE
followed by one first-contact accept replaced the file with a single record.
Every other host re-TOFUs, and one whose key genuinely changed in between is
accepted as first contact rather than refused — the exact outcome pinning
exists to prevent. It also contradicted the doctrine this PR applies to
known_hosts two files away, where a file that exists and refuses to open is
evidence withheld.

Fixed by classifying one read instead of guessing twice: readStore returns
ok/absent/withheld, the read path flattens withheld to 'nothing trusted' so it
still fails closed, and the write path declines. That subsumes the separate
newer-version probe, so trustHostKey now reads the file once inside the queue
rather than twice. The 'Trusted host key' log moved inside the branch that
actually writes — it was already claiming success on the newer-version path.

P2 — the site-config scanner documents 'doubt wins on every path' and had
three where it did not, each the same shape: a path resolved WRONG still
resolves to something, and a nonexistent Include reads as 'nothing there',
which is indistinguishable from 'no policy'. Verified against OpenSSH 10.2p1:
relative Includes resolve against a fixed dir, not the including file's, so a
directive two deep was missed; ? and [...] are globs it honours; ~ and %-tokens
expand before use. All three now answer doubt.

P2 — credential prompts are gated on the attempt generation in one place
rather than per rung. A superseded attempt is denied without a recorded
decision, so isHostKeyVerificationError reads false and the ladder ran on to
prompt for a passphrase nobody was waiting on.

P2 — resolveKnownHostsFiles is async. Its rejoin existsSync-scans the very
paths the 5s bound protects, and sat outside it as an eagerly-evaluated
argument, so a stalled NFS/SMB mount blocked the whole main process.

Tests fail against the pre-fix code: 2 for the store wipe, 3 for the scanner.

Also: the 4 IME failures I previously reported as pre-existing main breakage
were a stale node_modules — the xterm patch from #14758 was not applied here
(402,643 bytes installed vs 403,181 expected). pnpm install applies it and all
4 pass. The OSC8 and SFTP failures were the same cause.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ition (stablyai#14758)

Backspacing over the last radical of a Cangjie composition empties the IME's
marked text without reaching compositionend, and the vendored xterm
CompositionHelper only dropped the overlay's `active` class there. The box
stayed painted with whatever glyph it last held (stablyai#11951).

Clear on the state rather than on the key, as native terminals do: an empty
`compositionupdate` now hides the overlay instead of only ever showing it, and
a key the IME swallows re-derives the preedit from the textarea once it settles
so a composition emptied with no composition event at all is cancelled too.
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]: Cangjie preedit text remains visible after Backspace cancels composition

2 participants