Skip to content

fix(terminal): open Firefox's IME candidate window at the preedit - #2962

Merged
devswha merged 5 commits into
mainfrom
fix/firefox-ime-caret
Nov 5, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/firefox-ime-caret

Conversation

@devswha

@devswha devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Fixes #2936.

Cause

Firefox places an input method's candidate window as if the text in xterm's helper textarea were never scrolled. That textarea is one or two cells wide, white-space: nowrap; overflow: hidden, and keeps everything typed since the last Enter. Once a few words are on the line, the preedit at its end sits scrolled out of the box, and Firefox opens the candidate window that far left of it: it stays near where the line's typing began. Chromium (Edge) puts it on the preedit.

Change

  • patches/@xterm%[email protected] (CompositionHelper.updateCompositionElements): while composing in Firefox, the helper textarea grows to the left by its overflow (scrollWidth - clientWidth), keeping its right edge, where the preedit ends, in place. Nothing in it scrolls, so the preedit is where Firefox looks for it. Other browsers are untouched, and the right edge does not move, so the host still never pans sideways (Terminal: a too-wide grid scrolls right on every text insertion or IME composition #1492).
  • scripts/xterm-composition.test.ts: builds the helper as Firefox sees it (Platform reads the user agent) and checks that the text typed before a preedit leaves no overflow while the box's right edge stays at the end of the drawn preedit. It fails on the previous patch (Expected: 27, Received: 112) and passes with this one.
  • Changelog fragment.

Native check (Windows 11 VM, Firefox 159, Microsoft Pinyin, 1920x1080)

An isolated diagnostic server (test herdr session, scripts/terminal-ime-diagnostic.ts with geometry tracing added locally, not committed) driven with real keyboard input through the OS input method. The table shows the candidate bar's left edge minus the preedit's left edge, from screenshots:

Typed before the preedit on the line Firefox, main Edge, main Firefox, this branch
4 words, composing shu'ru'fa -56 px +8 px +8 px
9 words, composing shi'jie -228 px +8 px +6 px

On main, Firefox's bar stayed at the same x for every word of the line while the preedit moved right. The trace showed the helper textarea at the cursor with scrollLeft growing with the line (62 to 253 px). Forcing the textarea wide (3000 px, so it never scrolls) put the window on the text in Firefox, which confirmed the cause before the fix. The Microsoft Korean IME's Hanja candidates showed the same displacement on main.

The intermittent typing stutter in the report was not reproduced or measured here, and is not addressed by this change.

Validation

  • bun test scripts/xterm-composition.test.ts: 11 pass; the new test fails on main's patch.
  • bun run check fast: pass.
  • No visible UI change (the textarea is invisible), so no screenshots of the app's own layout.

Firefox places an input method's candidate window as if the text in
xterm's helper textarea were never scrolled. The textarea is one or two
cells wide and keeps the text typed since the last Enter on one unwrapped
line, so the preedit at its end sat scrolled out of the box, and the
candidate window opened that far left of the cursor (near the start of the
line). Edge, given the same page and keys, puts it on the preedit.

While composing in Firefox, the textarea now grows to the left by its
overflow, keeping its right edge (the end of the preedit) where it was, so
nothing in it scrolls.

Fixes #2936
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • In Firefox, Chinese, Japanese, and Korean input method candidate windows now appear beside the text being entered, including after several words.
    • Improved composition and dictation input behavior across supported browsers and devices.
    • Restored Alt+Left/Right word navigation and corrected trackpad scrolling behavior.
  • New Features
    • Added public methods to finish pending text composition, set textarea viewport bounds, and inspect OSC parser state.

Composition rendering now positions the textarea using cursor and viewport bounds and adjusts its placement when Firefox reports horizontal overflow. A Firefox-specific test checks placement after existing text. A changelog entry describes candidate-window positioning for Chinese, Japanese, and Korean input methods.

Changes: Firefox IME candidate placement

Layer / File(s) Summary
Composition positioning and validation
patches/@xterm%[email protected], scripts/xterm-composition.test.ts, changelog.d/firefox-ime-candidate-window.md
Composition rendering uses cursor and viewport bounds, limits rendered width, and shifts overflowing text so its end remains visible. For Firefox, the textarea moves left by its overflow and expands by the same amount. The test checks textarea width and alignment after existing text. The changelog describes the candidate-window change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: zs311521

Merge Risk: Minimal · up to 4da7d

The Firefox placement change has no established blocking defect. A non-Firefox placement test would strengthen protection against unintended changes in other browsers.

- [ ] 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

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review round (omo: CLEAR at f4287db; Codex Terra 6.1, xhigh reasoning: one MEDIUM, one LOW, neither reproduced):

  • MEDIUM, kept as is (not reproduced): while a Firefox composition runs, the widened helper textarea can start left of the visible host (for example, when the cursor is clamped to the left bound). That part of the box is the text typed before the preedit, which Firefox's candidate window needs unscrolled; clamping the left edge back inside the bounds would scroll that text again and bring the displacement back. The box's right edge, where the caret and preedit end, does not move, so nothing the browser keeps in view moves either: the rightward host pan from Terminal: a too-wide grid scrolls right on every text insertion or IME composition #1492 came from the caret moving past the right edge. The textarea is invisible. In the native Firefox runs (Windows 11, Microsoft Pinyin, up to nine words on a line), the terminal host never panned. The wider box lasts until the next cursor move redraws it, which is the echo of the committed text.
  • LOW, fixed in 4718705: the new test now puts the preedit in the textarea after compositionupdate, as browsers do, and lets the deferred update measure it. It still fails on main's patch (Expected: 27, Received: 112).

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): bun run check fast passed at this head, omo CLEAR, threads resolved, merges cleanly. Verified natively in winvm with Microsoft Pinyin: candidate window offset from the preedit, Firefox main -56/-228 px -> +8/+6 px (Edge +8/+8). Merged without waiting for GitHub CI.

@devswha
devswha merged commit 7728cc8 into main Nov 5, 2026
11 of 12 checks passed
@devswha
devswha deleted the fix/firefox-ime-caret branch November 5, 2026 11:17
devswha added a commit that referenced this pull request Nov 5, 2026
Fixes #2432

## What

Behind **Settings > Appearance > Lock pinned agents (experimental)**
(shared, off by default), a pinned row in the Agents list can be locked
so this app cannot close it by accident:

- **Lock agent** in the row's menu (the phone sheet's ⋯, a desktop
right-click), next to Pin agent, shown only for pinned rows.
- A locked row hides **Unpin agent** until **Unlock agent**, and draws a
small lock beside its state (named "Locked" for a screen reader and the
tooltip, drawn as the muted bell is).
- While locked, this app offers no way to close it: no **Close pane** in
the pane's menu, and no **Close tab** for the tab it is in (tab menu,
the pane menu's lone-tab items, the Delete key and middle click on the
tab).
- The locks are a shared setting, `lockedAgents` (pin keys), so every
browser and the phone apps honour them. A lock holds only while its row
is pinned, leaves when its pin leaves, and moves with its pin when herdr
moves the pane (#1503).
- Closing from herdr itself, the Herdr app or a script is unaffected.

Note: on current main the agent row's own menu never offered Close (the
issue's wording); the closes this guards are the pane and tab ones
above.

Default: the setting is off, so the Agents list offers no Lock agent and
no lock holds; today's behaviour is unchanged. Nothing is added to the
chat composer.

Why experimental: the lock-state gaps listed in #2977 (concurrent saves
across browsers, storage that refuses writes) are not handled yet. The
two close paths the second review reproduced are fixed here,
fail-closed: a tab's lock is checked by every pane in it by id, and a
workspace or group close goes unsent when the workspaces or panes it
would take differ from those its confirmation was opened over.

## Design reference

Browsers' pinned tabs keep their place but can still be closed; this
follows them for the pin and adds the missing lock as an item in the
row's own menu, as Mute alerts already is. The lock itself follows VS
Code's Lock Group rather than the coding-agent apps (the Codex and
Claude apps, Paseo, T3 Code), which give a session no lock; their
sessions are not a control pane that drives the others (DESIGN.md
updated).

## How

- `src/lib/paneLocks.ts`: `lockedPinKeys` (locks that hold: those still
pinned), `toggleAgentLock`, and `usePaneLocked(machineId)` for the menus
that close panes and tabs.
- `lockedAgents` added to Settings (default `[]`, sanitized to distinct
non-empty strings, at most `MAX_PINS`), marked shared, and to
`SHARED_SETTING_KEYS` so the server keeps it. It is not collected by
telemetry.
- `AgentSidebar`: Lock/Unlock item, lock glyph, locks pruned with the
pins.
- `PaneCanvas` / `TabStrip`: Close pane / Close tab left out for locked
panes; `requestClose` in the tab strip refuses a locked tab, which
covers Delete and middle click.
- `Sidebar`: Close workspace, Close group and Delete worktree checkout
are left out when a workspace they would close holds a locked agent.
- A close confirmation already open when a lock arrives (from another
browser) is dismissed; the phone tab menu no longer falls back to a
stale Close pane action that the canvas stopped offering.
- A watching device sees Lock/Unlock disabled, as Mute alerts is.
- `agentLocks` (shared, default `false`) gates the item and every guard;
the Settings row is on the Appearance page beside Group agents by state.
- `App`: a moved pane's lock follows its pin.

## Validation

- Failing first: the five new tests failed on main (129 pass, 5 fail),
then pass; the workspace-menu test added in the review round failed
without the Sidebar change and passes with it.
- `bun test src/lib/paneLocks.test.ts src/lib/settings.test.ts
src/lib/preferencesSync.test.ts src/components/PaneCanvas*
src/components/TabStrip* src/components/AgentSidebar* src/lib/i18n
server/preferences.test.ts`: 243 pass, 0 fail.
- `bun scripts/agent-lock-demo-regression.ts` (new, demo fixtures): PASS
at 390 and 1280, light and dark, with the setting on; it also captures
the Settings row. Only a pinned row locks; a locked one keeps its pin
and draws the lock; its tab offers no Close tab; unlocking brings Unpin
back; no sideways scroll; no page errors.
- `bun run check fast` on the head after the review fixes, after `bun
install --frozen-lockfile` (an earlier run had a stale xterm patch from
#2962 installed, which made `scripts/xterm-composition.test.ts` fail
falsely): all steps ok (workflow syntax, generated types and themes,
typecheck, build, unit tests)
- New browser script registered in `scripts/ci-browser.sh` (Integration
and browser lane).
- Skipped: `check full`, native Windows/macOS (client-only change; no
server, workflow or packaging change beyond the shared setting name).
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.

Terminal: Firefox IME candidate window is displaced from the input caret, with intermittent typing stutter

1 participant