Repository navigation
fix(terminal): align CJK IME preedit spacing - #19367
Conversation
|
This looks like the same defect as #18293, which I filed on 9/3 — mid-line Hangul drawn one cell wide where the grid gives it two. The |
Not sure Would be awesome if it is the same |
85bc768 to
42ce57a
Compare
|
Important Review skippedWe couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe patch updates xterm IME handling to track composition transactions, reconcile keypress and input events, defer finalization, and clean up on cancellation, blur, and disposal. It adds grapheme-aware preedit rendering with cell-width corrections, bounded font measurements, caret and row-tail elements, and font-load refreshes. Unit, regression, and end-to-end tests cover rendering, shaping, alignment, continuity, cleanup, and single-commit behavior. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to The required lint workflow currently fails on two new test helpers. Replace the reflective reads or add justified scoped suppressions before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 28e58cf3-b129-4ba0-8efa-bf9ea0bbf899
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
config/patches/@[email protected]config/patches/xterm-src/@[email protected]docs/reference/ime-regression-checklist.mdsrc/renderer/src/components/terminal-pane/terminal-ime-xterm-midline-preedit-tail.test.tssrc/renderer/src/components/terminal-pane/terminal-ime-xterm-preedit-cell-grid.test.tstests/e2e/terminal-ime-preedit-cell-grid.spec.tstests/e2e/terminal-ime-preedit-continuity.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| const core: unknown = Reflect.get(terminal, '_core') | ||
| if (!isImeTerminalCore(core)) { | ||
| throw new Error('xterm internals are unavailable') | ||
| } | ||
| return core | ||
| } | ||
|
|
||
| function isImeTerminalCore(value: unknown): value is ImeTerminalCore { | ||
| const renderService = objectProperty(value, '_renderService') | ||
| const dimensions = objectProperty(renderService, 'dimensions') | ||
| const css = objectProperty(dimensions, 'css') | ||
| const cell = objectProperty(css, 'cell') | ||
| const compositionHelper = objectProperty(value, '_compositionHelper') | ||
| return ( | ||
| typeof objectProperty(cell, 'width') === 'number' && | ||
| typeof objectProperty(compositionHelper, 'updateCompositionElements') === 'function' | ||
| ) | ||
| } | ||
|
|
||
| function objectProperty(value: unknown, key: string): unknown { | ||
| return typeof value === 'object' && value !== null ? Reflect.get(value, key) : undefined |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'no-reflect-get|anti-slop|Reflect\.get' package.json pnpm-lock.yaml .github config scripts src/renderer/src/components/terminal-pane/terminal-ime-xterm-preedit-cell-grid.test.ts 2>/dev/null
rg -n '"(lint|check|typecheck|test)[^"]*"\s*:' package.json packages/*/package.json apps/*/package.json 2>/dev/nullRepository: stablyai/orca
Length of output: 16713
🏁 Script executed:
printf '%s\n' '--- package scripts ---'
sed -n '1,35p' package.json
printf '%s\n' '--- anti-slop config ---'
sed -n '1,125p' config/oxlint-anti-slop.json
printf '%s\n' '--- PR workflow ---'
sed -n '125,148p' .github/workflows/pr.yml
printf '%s\n' '--- changed-code checker ---'
sed -n '330,360p' config/scripts/check-changed-code-quality.mjsRepository: stablyai/orca
Length of output: 10093
Resolve the anti-slop/no-reflect-get lint errors.
anti-slop/no-reflect-get is configured as an error. The audit scans src, and both lint and the PR workflow run this audit. Both Reflect.get calls therefore fail the ordinary lint workflow.
Replace the dynamic reads with typed property access, or add a scoped disable with a reason.
♻️ Proposed fix using typed access
function rendering() {
- const core: unknown = Reflect.get(terminal, '_core')
+ const core: unknown = (terminal as unknown as { _core?: unknown })._core
if (!isImeTerminalCore(core)) {
throw new Error('xterm internals are unavailable')
}
return core
}
@@
function objectProperty(value: unknown, key: string): unknown {
- return typeof value === 'object' && value !== null ? Reflect.get(value, key) : undefined
+ return typeof value === 'object' && value !== null
+ ? (value as Record<string, unknown>)[key]
+ : undefined
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const core: unknown = Reflect.get(terminal, '_core') | |
| if (!isImeTerminalCore(core)) { | |
| throw new Error('xterm internals are unavailable') | |
| } | |
| return core | |
| } | |
| function isImeTerminalCore(value: unknown): value is ImeTerminalCore { | |
| const renderService = objectProperty(value, '_renderService') | |
| const dimensions = objectProperty(renderService, 'dimensions') | |
| const css = objectProperty(dimensions, 'css') | |
| const cell = objectProperty(css, 'cell') | |
| const compositionHelper = objectProperty(value, '_compositionHelper') | |
| return ( | |
| typeof objectProperty(cell, 'width') === 'number' && | |
| typeof objectProperty(compositionHelper, 'updateCompositionElements') === 'function' | |
| ) | |
| } | |
| function objectProperty(value: unknown, key: string): unknown { | |
| return typeof value === 'object' && value !== null ? Reflect.get(value, key) : undefined | |
| const core: unknown = (terminal as unknown as { _core?: unknown })._core | |
| if (!isImeTerminalCore(core)) { | |
| throw new Error('xterm internals are unavailable') | |
| } | |
| return core | |
| } | |
| function isImeTerminalCore(value: unknown): value is ImeTerminalCore { | |
| const renderService = objectProperty(value, '_renderService') | |
| const dimensions = objectProperty(renderService, 'dimensions') | |
| const css = objectProperty(dimensions, 'css') | |
| const cell = objectProperty(css, 'cell') | |
| const compositionHelper = objectProperty(value, '_compositionHelper') | |
| return ( | |
| typeof objectProperty(cell, 'width') === 'number' && | |
| typeof objectProperty(compositionHelper, 'updateCompositionElements') === 'function' | |
| ) | |
| } | |
| function objectProperty(value: unknown, key: string): unknown { | |
| return typeof value === 'object' && value !== null | |
| ? (value as Record<string, unknown>)[key] | |
| : undefined |
🧰 Tools
🪛 GitHub Check: static analysis
[failure] 67-67: anti-slop(no-reflect-get)
src/renderer/src/components/terminal-pane/terminal-ime-xterm-preedit-cell-grid.test.ts:67:56: Replace Reflect.get with typed property access. Parse dynamic input into a named domain type before reading it.
[failure] 47-47: anti-slop(no-reflect-get)
src/renderer/src/components/terminal-pane/terminal-ime-xterm-preedit-cell-grid.test.ts:47:25: Replace Reflect.get with typed property access. Parse dynamic input into a named domain type before reading it.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed all 8 changed files at 42ce57a (7 commits) against main (3af09f8).
- CJK preedit cell-grid correction — the xterm source patch adds
CompositionPreeditRenderer, which segments the preedit withIntl.Segmenter, measures each single-codepoint CJK grapheme with the existingWidthCacheFontVariantCanvas, and wraps equal-correction runs in inline spans whoseletter-spacing: calc(var(--xterm-composition-cell-width) * columns - measuredWidth px)makes each run advance by exactlycolumns × cellWidth. Marks, emoji, multi-codepoint clusters, and non-CJK text stay as plain text nodes so native shaping is preserved. AMAX_PREEDIT_LAYOUT_WORK = 128budget bounds cold measurements plus styled runs, leaving the uncorrected tail native. - Repaint preservation —
_renderCompositionViewis split so a row repaint updates only the covered-tail node (_renderCompositionRemainder), keeping the preedit and caret DOM nodes stable;--xterm-composition-cell-widthis published on the view so a resize re-aligns spans without re-measuring; the helper textarea anchors to the preedit rect rather than the whole view. WidthCacheFontVariantCanvasexport — exported so the renderer can reuse xterm's font measurer.- Tests/docs — a new 36-case unit suite plus two Electron/CDP e2e specs assert grid alignment, prefix continuity, native shaping, and bounded work; the midline-tail test now pins node identity across repaints;
ime-regression-checklist.mddocuments the invariant. - Generated artifacts — the bundled
.patchandpnpm-lock.yamlpatch hash are regenerated in sync (the lockfile hash matches thesha256of the bundled patch).
I verified the source-level delta by reconstructing both patches' new-side sources: the only semantic changes are the renderer, the render/remainder split, the constructor param, the WidthCache export, and the trailing newline — the pending-composition/transaction hunks visible in the diff-of-patch are alignment noise, not source changes. All 13 terminal-ime-xterm-* unit files pass (177 tests), and pnpm run typecheck:web is clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
42ce57a to
46e41ae
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the two commits landed since the prior pullfrog review (42ce57a); both are test-only.
- Removed reflective internals access in the grid unit fixture —
rendering()narrows through ahasTerminalCoretype guard and readsterminal._coredirectly, andisImeTerminalCorewas rewritten with anisRecordhelper, dropping bothReflect.getcalls thatanti-slop/no-reflect-getflagged. - Tagged the WebGL grid matrix
@headful— the DPR × GPU describe now runs in theelectron-headfulproject, sosetTerminalGpuAcceleration('on')exercises a real WebGL context rather than failing thesample.webglassertion under the headless project. The untagged native-shaping test in the same file stays headless.
The production xterm patch and lockfile are unchanged since 42ce57a. I re-applied the current patch locally and confirmed the 36-case unit suite passes, pnpm tc:web is clean, and oxlint reports no findings on both changed files.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — reviewed the single commit landed since the prior pullfrog review (46e41ae); it is a CI-unblocking editor refactor unrelated to the IME work.
- Restored
DiffViewerunder themax-linesbudget — replaced the localisDarkcomputation with the sharedresolveDocumentTheme(settings?.theme ?? 'light')and folded the two font-size consts together, droppingDiffViewer.tsxfrom 402 to 400 counted lines. Repo-wideoxlintwas already failing onmainat 402 lines (confirmed via the failedstatic analysisjob on46e41ae:DiffViewer.tsx:445:2: File has too many lines (402).), so this repairs a pre-existing breakage rather than one the IME commits introduced. - Behavior preserved —
resolveDocumentThemereturns the same value as the removed expression for'dark','light','system', and a missing setting;document-theme.test.tsalready covers thematchMediapath, and noDiffViewertest pins the old expression.
The IME production patch, lockfile, and test files are unchanged since 46e41ae. The PR remains a draft and its author notes the aggregate CI run is still pending; this review covers the incremental delta only.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
b5440c1 to
9d249b9
Compare
CompositionHelper built the rendered row tail from translateToString, which returns characters and drops every cell attribute, so a dim placeholder or a coloured prompt came back in the default foreground and read as entered text. The tail is now emitted as runs that share a rendered style, each carrying what the grid resolved for it: palette, RGB and default foregrounds, backgrounds, dim, bold, italic, inverse, invisible, underline style and colour, strikethrough and overline. A run that needs no override stays a bare text node, so a default tail emits exactly the DOM it did before. Re-cut onto stablyai#19367, which split the remainder into its own renderer so a row repaint keeps the preedit and caret nodes. The runs go inside that renderer and the refresh is keyed on text and styling together, since a repaint that only recolours a row leaves its characters identical. Fixes stablyai#16025

ELI5
Japanese IME text can spread farther apart while composing than after confirmation. With the reported UDEV Gothic NF font at 13px and DPR 1, eight characters now occupy the same 96px as committed text, without resizing the glyphs. Appending ASCII or emoji preserves the existing Japanese prefix.
What Changed
Why
Stock xterm reproduces the mismatch: WebGL rounds the half-cell to 6px, while native preedit text advances 13px per fullwidth glyph. Orca's inherited letter spacing adds another 0.16px per glyph. Resetting inherited spacing alone leaves the primary mismatch. CompositionHelper already owns this overlay and has no public extension point for its layout, so the existing source patch remains the appropriate boundary.
The work budget applies to new measurements and styled spans, rather than switching an entire composition between layout modes. A repeated 10,000-character CJK string uses one measurement and one span. Expensive alternating or varied text keeps its remaining tail in native layout after the budget is consumed. That tail, and unsupported multi-codepoint clusters, deliberately retain the original spacing; this is not universal grid parity for arbitrary text.
Linked Issue
Fixes #19315.
Other open IME reports were checked; no confirmed duplicate or additional fix is claimed. #18963 concerns dictation flicker, #19284 Cursor-specific Korean input, #19156 disappearing Korean characters, #15192/#15550 duplication/disappearance, and #18283 a separate mobile patch gap.
Visual Proof
Native Japanese input on the M4 Air reproduces the original problem and verifies the fix with the same UDEV font, size, and DPR. Both builds commit the exact eight characters once. Actual Electron captures, cropped and enlarged without smoothing:
The following hidden-renderer captures compare committed text with preedit and verify prefix continuity after appending ASCII:
Testing
Production patches and lockfile are byte-identical to
1db4dc04; subsequent commits only correct the regression fixture's subpixel tolerance and available width. Remote installed source and runtime hashes were checked, not just checkout names.pnpm tc:web, changed-code quality, frozen install, E2E build, and generated xterm patch reproducibility pass.85bc7687, preserving DPR 1/1.25/2. Chromium's per-inline-run 1/64px rounding is accounted for; repeated CJK retains a 0.05px tolerance. The owned test window is sized to avoid wrapping the committed reference.Hosts were discovered with
orca host list; dedicated checkouts, remote shells, and evidence retrieval used Orca CLI. Native input used OS keyboard injection and actual input sources; renderer inspection used Playwright/CDP. Native, hybrid, and synthesized-event coverage are distinguished below.awin)85bc7687resolves both earlier reference-wrapping failuresopenclaw, private Xvfb)Windows native Japanese screenshot · Windows native Korean screenshot · Linux native Hangul preedit screenshot
Windows's five patch-generator test failures exercise unchanged baseline path normalization; the generator and its test are identical to main. Linux initially required a process-local Mesa/software renderer selection to avoid an Xvfb/NVIDIA startup crash. Neither prompted a production change.
Four matched warm browser batches preserve all text across 1,024 measured updates and emit no PTY data. Median handler times (UDEV 13px, DPR 1, WebGL):
A further 36 fresh Electron runs produced 72 paired cold samples with reversed variant order, exact text, and zero data events. First-position WebGL medians (base/current): 8.3/10.2ms for 128 CJK, 17.0/19.1ms for 10k distinct Han, and 27.8/30.7ms for 10k alternating CJK/Latin. The earlier unmatched 51ms observation did not recur; the largest current handler was 30.7ms (DOM: 30.3ms). OS font caches were not flushed. Alternating stress exceeds a frame in the baseline too; this does not establish a universal latency bound.
Owned remote test apps were closed, original macOS/Windows input sources and focus were restored, and Windows temporary install settings were restored. Linux host inspection confirmed no remaining test processes and a restored current build; some older shell-close receipts remained unverifiable and were not treated as confirmed exits. Local validation stayed background-only. Windows input was injected on the remote host during an active RDP session; this does not test keyboard forwarding through RDP.
Review
Functional, performance/resource, and compatibility sub-agent reviews completed against the readiness checklist. No proven new defect remains within the documented scope. Review covered source/bundle integrity, disposal, bounded allocations, font invalidation, native shaping, prefix continuity, and client/host boundaries. The final test-only delta was independently re-reviewed. Zero candidate findings remain, so severity counsel was not required.
Agent skill upstream boundary
Notes
This changes client-side provisional text rendering. It adds no PTY bytes, protocol, persistence, process, SSH execution, or workspace-type assumptions. Paired web shares this renderer; native mobile has a separate package graph.
Remaining coverage limits: Windows Chinese delivered exact converted text through an OS route with no DOM composition events, so it does not verify xterm preedit. Linux full-native Enter failed identically on baseline (no native Return key events in this background harness); native Japanese/Mozc activation remains unproven. Linux WebGL used SwiftShader on private Xvfb; physical GPU/Wayland behavior was not exercised. Safari/paired-mobile rendering, WSL/RDP-specific IME forwarding, and live terminal SSH network-fault scenarios were not tested. Operating the Linux evaluation host over SSH does not certify those failure paths.
The PR remains a draft. At
85bc7687, the test-LoC check passed, but PR Checks were manually cancelled before validation completed; the aggregate verify job was still queued at the last check. Current-head CI is not green: require a passing run before merge. No universal zero-regression guarantee is claimed.Checklist