Repository navigation
fix(terminal): open Firefox's IME candidate window at the preedit - #2962
Conversation
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
|
Caution Review failedThe pull request is closed. Summary
Merge Risk:
|
|
Review round (omo: CLEAR at f4287db; Codex Terra 6.1, xhigh reasoning: one MEDIUM, one LOW, neither reproduced):
|
|
Local merge gate (owner-approved): |
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).
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.Native check (Windows 11 VM, Firefox 159, Microsoft Pinyin, 1920x1080)
An isolated diagnostic server (test herdr session,
scripts/terminal-ime-diagnostic.tswith 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:shu'ru'fashi'jieOn 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
scrollLeftgrowing 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.