Repository navigation
fix(terminal): keep a long IME composition's newest characters in view - #2031
Conversation
Since devswha#1800 a long composition in Direct typing was clipped at the right edge from the cursor, hiding the characters being converted. The box now moves left when the room to the edge is too small, and shows its end when it is wider than the terminal, while the helper textarea keeps devswha#1534's bounds so the host never scrolls sideways (devswha#1628). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Composition input and terminal state APIs patches/@xterm%[email protected] |
The patch updates composition handling for Safari replacement edits, Hangul input, dictation, and deferred sends. It adds public APIs for finishing composition, setting textarea viewport bounds, and reading OSC string state. |
Composition visibility and regression checks patches/@xterm%[email protected], scripts/terminal-composition-regression.ts, changelog.d/terminal-preedit-tail.md |
The composition view is constrained to valid viewport bounds and shifts overlong text so its end remains visible. The regression script checks visibility for long and Japanese compositions. The changelog describes the Direct typing behavior. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related issues
- devswha/herdr-web-ui issue 1492 — It reports sideways host scrolling during IME composition and insertion. The patch changes composition-view placement and textarea bounds, which share that issue’s mechanism.
Suggested reviewers: devswha
Merge Risk: 
Minimal · up to 5a914
-
No actionable issue was established for this change; it is ready to merge after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Verified at 2e1dc63, rebased locally onto current main (7c0f34c) without conflicts.
Not run here: native Windows and physical IMEs. |
|
Thanks @yaaayaaa. The merge-pass gate found the patch limited to preedit layout. Commit, pty input and keyboard handling are unchanged. A frozen install applies it cleanly, and the build, typecheck, all 9 composition cases and conventions pass. The new regression fails on the pre-change build (last glyph x=593 against a clipped box edge x=398). One small request: please add the contributor credit to |
|
Correction from the merge pass: no changelog change is needed after all. Per changelog.d/README.md, a maintainer adds |
|
Merge pass review report. Overall: PASSED. This outside contribution from @yaaayaaa changes the xterm patch so a long IME composition keeps its newest characters in view. The maintainer approved merging it once the gate passed, and the gate (omo-native-gate-reviewer, gpt-6-astra) passed it. Gate verification:
My own check: I merged it locally into main (c6f77d7). This PR touches A maintainer adds the changelog credit when the release folds the fragments (changelog.d/README.md). |
## Release 0.4.19 The release PR, made by the steps in [docs/development.md#releasing](docs/development.md#releasing), on main 9d76cca (#2078): - **Version:** `version` is 0.4.19 in `package.json` and `herdr-plugin.toml`. - **Changelog:** `bun scripts/changelog-fold.ts 0.4.19` moved the `changelog.d` fragments of 54 PRs into CHANGELOG.md, with PR links, and deleted them. - Outside contributors are credited: #1955 @YuuuXie, #1957 @Noobear, #1984 @bonecool999, #2003 @philipprass-prog, #2016 @kyop21, #2024 @YuuuXie, #2025 @YuuuXie, #2027 @jpcarranza94, #2030 @phlips5437, #2031 @yaaayaaa, #2034 @jpcarranza94, #2035 @nahwan-kim, #2041 @odfalik, #2045 @mattmarcin, #2052 @jpcarranza94, #2057 @kyop21, #2061 @YuuuXie. - **Release summaries:** `release-summaries.json` has the 0.4.19 entry in en, ko, ja and zh, with the same lists in each: 5 new, 5 improved, 5 fixed. Every English line is at most 70 characters. - **Remote bundle:** `REMOTE_BUNDLE_VERSION` goes from 37 to 38 in `shared/machines.ts`, because the remote bundle's inputs changed since `remote-v37`. Once this merges, `remote-v38` is pushed on the merge commit, and the Remote PC bundles workflow has to finish before the Release run. `bun scripts/release-guards.ts` reports: "Release 0.4.19: remote bundle, telemetry Worker and release metadata are in order." No telemetry Worker deploy is needed. `bun run check fast` passes locally. **Not checked on a real Windows PC:** #1989 (Git for Windows' OpenSSH for remote PCs) and #2016 (Antigravity chat on Windows through the Restart Manager) ship without their real-device Windows checks, because the maintainer's Windows test PC is off. The owner accepted releasing without them. Both will be checked on the real PC when it is back. The owner approved this release.
) (#2335) ## Change Closes #1617. Targets 0.4.20 (the owner moved it in from 0.4.21). This upgrades xterm.js from 5.5.0 to 6.0.0, so a terminal draws only whole frames: xterm 6 honours synchronized output (DEC mode 2026, xtermjs/xterm.js#5453). Ovis's xterm source patch is ported to 6.0.0. It follows #2331 (merged), whose regression script measured the problem; this PR makes that script assert zero half-drawn frames. **Why:** herdr sends every frame it draws inside `CSI ? 2026 h` … `l`, and large frames reach the browser split over several WebSocket frames. xterm 5.5 ignored the brackets and painted whatever it had parsed so far: the top half of the new frame over the bottom half of the old one. The owner saw this while agents stream, most of all with Korean text. | `scripts/terminal-sync-output-regression.ts`, real pane, 162x53 | renders | mixed (two frames at once) | drawn inside an open block | |---|---|---|---| | xterm 5.5.0 (main), 3 runs | 128 / 108 / 110 | **46 / 26 / 28** | 46 / 26 / 28 | | xterm 6.0.0 (this PR), 3 runs | 82 / 82 / 82 | **0 / 0 / 0** | 0 / 0 / 0 | In every run, all 62 of herdr's blocks reached the browser intact, and 59-62 of them were split over WebSocket frames. 6.0 also renders fewer times (82 against 108-128), because it skips the intermediate paints. ## What changed - **Pins:** - `@xterm/xterm` 6.0.0, `@xterm/addon-fit` 0.11.0 (was `^0.10.0`) and `@xterm/addon-web-links` 0.12.0 (was 0.11.0). All three were released with 6.0.0 on 2025-12-22. - `@xterm/addon-unicode-graphemes` 0.4.0 is unchanged; it was already the 6.0 release. - **The patch** (`patches/@XTerm%[email protected]`, which replaces the 5.5.0 one): - The same 12 files, moved to 6.0's layout: `browser/Terminal.ts` is now `CoreBrowserTerminal.ts`, the `Types.d.ts` files are `Types.ts`, and 6.0 uses VS Code's lifecycle names (`_register`, `addDisposableListener`, `Emitter`). - 3 of 34 hunks needed hand-porting: - **Textarea blur:** ported to the new listener. - **`_finalizeComposition`:** ours replaces 6.0's. 6.0's only change there was its duplicate-input fix (#5024), slicing to a new composition's start, and our send already does that. - **DPR monitor disposal:** dropped, because 6.0 already registers it. - The key, keypress, keyup, input, paste, blur and focus handlers the patch touches are unchanged in 6.0 apart from one `scrollToBottom(true)`, so the IME paths are carried over as they were: - Safari/WebKit Hangul preedit, including the iOS app's WKWebView gate (#2307). - Dictation, the Gboard Backspace reset, the Linux digit candidate (#1654), the long-composition view (#2031) and #938/#1327. - Paste order, input reset, textarea placement and `oscStringState`. - **New hunk, `CoreMouseService.ts`:** keeps one wheel report per row of a trackpad's travel, as 5.5 counted it. 6.0 scales a pixel delta under 50 px by 0.3, which made scrolling a mouse-reporting program, herdr's history included, 3.3 times slower on a trackpad. - **New hunk, `Keyboard.ts`:** keeps Alt/Option+Left/Right as 5.5 sent them (`ESC b`/`ESC f` on a Mac, Ctrl's sequence elsewhere). 6.0 dropped that mapping (#5346), and docs/terminal-input.md promises Option+arrow moves by word. - **Building xterm's source:** `scripts/build-xterm.ts` and the Vite aliases resolve 6.0's `vs/*` sources and its `vs/nls` stub, and use xterm's own `useUnknownInCatchVariables: false` for them. The browser scripts that bundle xterm with `Bun.build` (`terminal-dispose-browser-qa.ts`, `chat-history-browser-qa.ts`) now share one plugin, `xtermSourcePlugin`, with the same resolution. `terminal-dispose-browser-qa.ts` had resolved only `browser/` and `common/`, through a second `plugins` key; the lane caught it. - **Tests:** - `scripts/terminal-dispose-browser-qa.ts`: 5.5 threw "dimensions" from a terminal disposed at once, and 6.0 does not, so both modes now assert no error. - `scripts/xterm-parser-state.test.ts` pins 6.0.0. The parser fields and states the OSC accessor reads are unchanged, and that test checks them. - `scripts/terminal-sync-output-regression.ts` now asserts 0 mixed renders and 0 renders drawn inside an open block. - **Docs and comments:** updated where the version mattered. `THIRD_PARTY_NOTICES.md` adds Microsoft's copyright for the `vs/base` code 6.0 bundles (MIT). ## 6.0 changes checked against Ovis - **#5263** (the helper textarea is read-only while `disableStdin`): Ovis sets `disableStdin` only where input is dropped anyway (observing, held, ended, unsupported). Drafts come from `onData`, which never fires then. A phone keyboard no longer opens on such a pane, which matches "an observer never types". - **#5096** (new viewport and scrollbar): we keep `scrollback: 0`, and fit 0.11 reserves no scrollbar width at `scrollback: 0`. Our `::-webkit-scrollbar` rule is now inert. - **#5462** (removed options): Ovis uses none of them. `_oscLinkService` (the OSC 8 lookup in `terminalFold.ts`) still exists. - **Mode 2026 left open:** every new stream resets xterm first, so mode 2026 never carries over. A pane switch calls `term.reset()`, and an attach or watch writes `ESC c` in stream order. The cached-tab path is bounded by xterm's 1 s safety timeout. A late joiner gets the last 2026 switch from `ReplayBuffer`. - **xtermjs/xterm.js#5801** (ED2 inside a 2026 block moves the viewport): this cannot happen here. I checked it with a real Claude Code 2.1.311 answer in Korean, plus a resize, on this branch. Across 238 blocks only one `ESC [2J` reached the browser, herdr's own first draw, because herdr re-renders the pane rather than passing Claude Code's erases on. xterm's viewport never had anything to scroll: its scroll range and scroll position stayed 0 on every render, since we keep `scrollback: 0`. The settled screen matched herdr's `pane.read` row for row, 14 Hangul rows included. - modifyOtherKeys: still not supported by 6.0, so `PaneTerminal` keeps sending Ctrl+Enter itself, as before. ## Evidence - `bun run check fast`: green on this head (8,566 unit tests pass, 0 fail). - **The browser lane** (IME, paste, OSC 52 replay, late join and every terminal script): CI's browser regression jobs run it on this head. A full local run is under way, and its result will follow in a comment. - Earlier local runs caught two problems, both fixed here: `terminal-dispose-browser-qa.ts` could not resolve 6.0's `vs/` sources, and `ui-contexts` failed on the usage-row race. - On this head, `terminal-dispose-browser-qa.ts`, `chat-history-browser-qa.ts`, `terminal-arrows-clicks-regression.ts`, `omo-question-wheel-regression.ts`, `ui-regression.ts` and `ui-contexts-regression.ts` pass locally. - **Changelog:** `changelog.d/xterm-6-whole-frames.md`. - **Device checks with native input**, main (`4485f4d6`, xterm 5.5) against this branch (`e3c33e32`). The later commits change only the wheel factor, tests and comments. | Surface | Typed | main | this branch | |---|---|---|---| | Mac Safari 27.0.1, Korean 2-set, native HID keys (test Mac) | `abc` 한글 Space 안녕하세요 Return, then 한 Backspace Return | exact, 30 bytes | exact, 30 bytes | | Mac Safari, Option+Left / Option+Right | | `ESC b` `ESC f` | `ESC b` `ESC f` | | iOS 27 simulator Safari, on-screen Korean keyboard (WebDriverAgent taps) | ㅇㅏㄴㄴㅕㅇ Space, 한 Backspace, Return, slow and unpaced | exact, 22 bytes | exact, 22 bytes | | Ovis iOS app (Debug build, WKWebView without a Safari token, #2307) | same | exact, 22 bytes | exact, 22 bytes | | Windows 11 VM, Chromium 153, Microsoft Korean IME through `SendInput` | 한 Backspace Return | `하\r` | `하\r` | | same | `abc` 한글 Space 안녕하세요 Return | identical bytes on both, with one extra DEL after Return on both (the test driver timed out at the same Return, so it may be the driver; not from this change) | same | Faster native typing than about one key per 0.75 s could not be driven reliably on the simulator. - **Windows CI steps in the VM** (`windows-install.test.ps1`, preflight, frozen install, build, the Windows test set, `windows-terminal-browser-qa.ts`): 7 of 7 pass on both main and this branch (45 tests pass, 1 skipped). ## Reviews - **omo-native-code-reviewer:** APPROVE; no CRITICAL or HIGH. - **M1, fixed:** 6.0's trackpad scaling. The patch now keeps one report per row, and `omo-question-wheel-regression.ts` gained a case that sends 12 untrusted pixel wheels of 0.55 rows and expects 6 reports; with 6.0's scaling it gets 2. - **Fixed LOWs:** an Alt+ArrowLeft assertion in `terminal-arrows-clicks-regression.ts`, so the kept mapping cannot silently drop again; and three comments. - **Not changed:** - **L1:** the read-only textarea is checked by reasoning; the device runs above typed only on panes that take input. - **L2:** a stream that stops inside a block now shows its half frame after xterm's 1 s timeout instead of at once. Every pane switch, attach and watch resets the terminal first, so this applies only to a cached tab's re-attach. - **Codex (gpt-6.1-sol, fast, xhigh):** APPROVE on the upgrade, with no findings at any severity. It compared every hunk; typecheck passed, and 2,571 targeted tests pass. - **Codex on the follow-ups** (the wheel hunk, the shared plugin, the test changes): REQUEST CHANGES, both fixed, then APPROVE with no findings. - **MEDIUM:** the Alt+ArrowLeft expectation now follows the page's platform (`ESC b` on a Mac), as xterm decides. - **LOW:** the dispose test again proves the deferral defers. With both modes now expecting no errors, the deferred case asserts the terminal is still alive after xterm's queued frames, and disposed only after the following task. - Codex checked that removing the Alt mapping, or disposing immediately, after the frame only, or not at all, makes those tests fail. - **CodeRabbit on #2331:** one nitpick. The harness should compare acked flow identities, not only counts. Done here. ## Also in this PR - `test(usage): …`: `checkUsageSignInAgain` (from #2309) counted Settings' account rows right after opening the page, before `/api/usage` had drawn them. It failed in 2 of 3 browser-lane runs on this branch and passed once on main. It now waits for the rows. - The browser lane's `ui-regression.ts` fails when TMPDIR is under `$HOME`, because the folder picker shows the path as `~/…`. This is a test assumption, not touched here; the lane was run with TMPDIR under `/tmp`.
Change
Since #1800 (v0.4.14), a long IME composition in Direct typing is cut off at the right edge of the
terminal: the box starts at the cursor and is clipped to the room left on the row, so the newest
characters, the ones being converted, are the ones hidden, often halfway through a wide character.
Japanese input reaches the edge after a few words. #1800 noted this as its tradeoff; v0.4.13 showed
the box whole.
The composition box now keeps its end in view while staying inside the visible terminal:
justify-content: flex-end), as asingle-line field, Ovis's own Input line included, keeps its caret in view.
The shift is
translateX(min(0px, calc(<room>px - 100%))), so it follows the width actually drawn:fitView(src/lib/terminalGlyphs.ts) resizes kana and Hangul after xterm measures the box, anda shift computed from the measured width came out 16px short for Japanese. The helper textarea keeps
#1534's bounds, so #1628 does not come back: the host never scrolls sideways.
Known limits:
clause that is hidden at the start keeps it hidden.
Validation
scripts/terminal-composition-regression.tsnow also checks that the newest character is insidethe box, and adds a Japanese composition at 412 px after 31 typed characters (longer than the
room to the edge, narrower than the grid) that must show whole.
412 direct default font: the newest character is in view(last glyph atx=704, box right edge at x=399); the Japanese case alone fails with its last glyph at x=564.
bun run check fast: typecheck and build pass. Unit tests: the same 9 files fail on main and onthis branch on my macOS machine (Linux home paths, timeouts), none related to the terminal.
Before and after
From the regression script's screenshots at 412 px, Direct typing. The Japanese row is the one the
test adds; the English row is #1800's existing composition, wider than the terminal.
🤖 Generated with Claude Code