Skip to content

fix(terminal): keep a long IME composition's newest characters in view - #2031

Merged
devswha merged 2 commits into
devswha:mainfrom
yaaayaaa:fix/terminal-preedit-tail
Oct 26, 2026
Merged

devswha merged 2 commits into
devswha:mainfrom
yaaayaaa:fix/terminal-preedit-tail

Conversation

@yaaayaaa

Copy link
Copy Markdown
Contributor

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:

  • one that fits the room right of the cursor is drawn at the cursor, as before;
  • one too long for that room moves left until its right edge meets the edge, so it shows whole;
  • one wider than the terminal fills it and shows its end (justify-content: flex-end), as a
    single-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, and
a 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:

  • A box moved left covers the committed text before the cursor until the word is committed.
  • A composition wider than the terminal shows its end, not the caret: moving back to an earlier
    clause that is hidden at the start keeps it hidden.

Validation

  • scripts/terminal-composition-regression.ts now also checks that the newest character is inside
    the 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.
    • On main: fails with 412 direct default font: the newest character is in view (last glyph at
      x=704, box right edge at x=399); the Japanese case alone fails with its last glyph at x=564.
    • With this change: all 9 cases pass, including the existing "not pushed sideways" checks.
  • bun run check fast: typecheck and build pass. Unit tests: the same 9 files fail on main and on
    this branch on my macOS machine (Linux home paths, timeouts), none related to the terminal.
  • Checked by hand with a Japanese IME on a preview build of this branch.

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.

Before and after: the composition box cut off at the right edge on main, and showing its newest characters with this change

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 8e8e369
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b8be60d-ecfa-48ef-b16c-02fd0edcaed1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 8e8e369
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d8bc209-2e8b-4774-848d-55960bfe22b1
Commits

Reviewing files that changed from the base of the PR and between 8e8e369 and 5a91466.

Files selected for processing: 3
  • changelog.d/terminal-preedit-tail.md
  • patches/@xterm%[email protected]
  • scripts/terminal-composition-regression.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Long input-method compositions now keep their newest characters visible when they extend beyond the space near the cursor or the terminal width.
    • Added terminal API options to constrain the text input area and finish an active composition. OSC string state is now available through the Terminal API.
  • Bug Fixes
    • Improved composition handling for Safari replacement edits, Hangul input, dictation, and overlapping composition updates.
    • Improved keyboard input handling in Linux and corrected text-area positioning within viewport bounds.

The xterm patch updates IME composition handling and viewport placement, and adds public APIs for composition completion, textarea viewport bounds, and OSC string state. The regression script checks that long and Japanese compositions remain visible in Direct mode.

Changes: IME composition and terminal API

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: Low

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: keeping the newest characters of long IME compositions visible.
Description check Passed The description includes both required sections. It explains the problem and resulting behavior, states known limits, and reports regression, build, test, and manual validation results.
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.
Full 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Verified at 2e1dc63, rebased locally onto current main (7c0f34c) without conflicts.

  • bun install --frozen-lockfile applies the updated xterm patch (checked the installed xterm.css and CompositionHelper.ts).
  • bun run check fast: exit 0, 7,429 pass / 0 fail / 24 skip.
  • scripts/terminal-composition-regression.ts: 9/9 cases pass, and scripts/terminal-input-regression.ts passes. With only the patch's new positioning removed, the composition script fails at "the newest character is in view" (box right 398, last glyph right 593), so the test guards the fix.
  • The 412px Japanese screenshot shows the whole preedit inside the right edge, and the host never scrolls sideways (Phone, Direct typing: a long voice-typing composition slides the terminal sideways and it stays there #1628 stays fixed).

Not run here: native Windows and physical IMEs. scripts/windows-lens-browser-qa.ts times out at its second-viewer step on this host on main too, so its IME checks say nothing either way. No findings. Thanks, @yaaayaaa.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner

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 changelog.d/terminal-preedit-tail.md, ending the entry with ([#2031](https://github.com/devswha/ovis/pull/2031) by @yaaayaaa) as other fragments do. After that it can be merged.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Correction from the merge pass: no changelog change is needed after all. Per changelog.d/README.md, a maintainer adds by @login for outside contributors when the release folds the fragments. Please ignore my earlier request. This PR merges as it stands, in its turn.

@devswha

devswha commented Oct 26, 2026

Copy link
Copy Markdown
Owner

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:

  • The patch only changes preedit layout. Committing a composition, pty input and keyboard handling are unchanged.
  • A frozen install applies the patch cleanly. The build, typecheck, all 9 composition cases and the conventions checks pass.
  • The new regression fails against the pre-change build: the last glyph sits at x=593, past the clipped box edge at x=398.

My own check: I merged it locally into main (c6f77d7). bun install --frozen-lockfile applied the patch, typecheck is clean, and the CI-style unit run passes 7423, with 0 failures.

This PR touches patches/, so it waits if a release window is open.

A maintainer adds the changelog credit when the release folds the fragments (changelog.d/README.md).

@devswha
devswha merged commit 2006290 into devswha:main Oct 26, 2026
11 checks passed
@yaaayaaa
yaaayaaa deleted the fix/terminal-preedit-tail branch October 27, 2026 07:34
@devswha devswha mentioned this pull request Oct 27, 2026
devswha added a commit that referenced this pull request Oct 27, 2026
## 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.
devswha added a commit that referenced this pull request Oct 29, 2026
) (#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`.
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.

2 participants