Skip to content

fix(webui): allow native text selection in chat via xterm.js bypass (#25720)#25777

Closed
wesleysimplicio wants to merge 1 commit into
NousResearch:mainfrom
wesleysimplicio:codex/fix-webui-mouse-selection
Closed

fix(webui): allow native text selection in chat via xterm.js bypass (#25720)#25777
wesleysimplicio wants to merge 1 commit into
NousResearch:mainfrom
wesleysimplicio:codex/fix-webui-mouse-selection

Conversation

@wesleysimplicio

Copy link
Copy Markdown
Contributor

Summary

Fixes #25720. The chat panel renders via xterm.js, and when the inner Hermes TUI enables mouse-events mode (CSI ?1000h family — used for nav inside Ink overlays/pickers) every drag, double-click, triple-click, and Option+drag in the canvas is consumed by the terminal instead of producing a native text selection.

Reporter (macOS, Brave) confirmed click-and-drag selects nothing, Cmd+C with no selection copies the entire visible buffer, and existing CSS overrides at the document layer have no effect — the issue is at xterm.js's mouse layer, not the DOM.

Fix

Two xterm.js options the user can opt into without disabling mouse-events mode for the inner TUI:

  • macOptionClickForcesSelection: true — holding Option (macOS) or Alt (Linux/Windows) during a click-and-drag bypasses mouse-events mode and produces a native xterm selection. This is the documented xterm.js path for exactly this scenario. Selected text is then copyable via Cmd+C / Ctrl+C through the existing OSC 52 + manual handlers already present in ChatPage.tsx.
  • rightClickSelectsWord: true — right-click highlights the word under the pointer. Single-action path on top of the modifier-based bypass.

Matches the issue's suggested fix #2 ("Ensure xterm.js Option-click selection bypass works as documented").

Why these two

The two options coexist with the existing macOptionIsMeta: true (which only affects keyboard, not mouse). The alternative — disabling mouse-events mode entirely — would break inner-TUI behaviour (overlays, pickers, scroll-via-mouse in Ink components), and the reporter explicitly noted suggestion #1 as one option among several. The modifier-key bypass is the lowest-impact fix that solves the reporter's actual workflow ("copy code snippets / commands / URLs out of agent output").

Solution sketch

flowchart TD
    A[User drags inside chat canvas] --> B{Mouse-events mode active?}
    B -- no --> C[Native selection works as today]
    B -- yes --> D{Option/Alt held?}
    D -- no --> E[Inner TUI consumes the drag]
    D -- yes --> F[xterm forces native selection]
    F --> G[Cmd+C copies selection via OSC 52]
Loading

Tests

web/package.json does not ship a test runner — only dev, build, lint, preview. The change is two configuration flags inside the existing new Terminal({...}) call. Verified:

  • All three flags (macOptionIsMeta, macOptionClickForcesSelection, rightClickSelectsWord) are documented xterm.js v6 options (the version in web/package.json: "@xterm/xterm": "^6.0.0").
  • The existing OSC 52 + Cmd+Shift+C handlers in ChatPage.tsx already pick up arbitrary xterm selections, so adding the bypass automatically routes selected text through the system clipboard.

Manual verification path for reviewers:

  1. macOS: open /chat, hold Option, drag across some agent output → highlight appears, Cmd+C copies.
  2. Linux/Windows: same with Alt instead of Option.
  3. Right-click on any word → that word is highlighted; Cmd+C / Ctrl+C copies just that word.

Duplicate check

  • gh pr list --state open --search "25720 in:body,title" → 0
  • gh pr list --state open --search "xterm macOptionClickForcesSelection rightClickSelectsWord" → 0

Funnel discipline

Opened under doc 23. Issue has 0 open competing PRs and no merged fix in the same area at time of opening.

…ousResearch#25720)

The chat panel renders via xterm.js, and when the inner Hermes TUI
enables mouse-events mode (CSI ?1000h family — used for nav inside
Ink overlays/pickers) every drag/double-click/triple-click in the
canvas is consumed by the terminal instead of producing a native
text selection. The reporter (macOS, Brave) confirmed:

- click-and-drag selects nothing
- Cmd+C with no selection copies the entire visible buffer
- existing CSS overrides and event handlers at the document layer
  have no effect — the issue is at xterm.js's mouse layer, not the
  DOM

Fix: two xterm.js options the user can opt into without disabling
mouse-events mode for the inner TUI:

- `macOptionClickForcesSelection: true` — holding Option (macOS)
  or Alt (Linux/Windows) during a click-and-drag bypasses mouse-events
  mode and produces a native xterm selection. This is the documented
  xterm.js path for this exact scenario. Selected text is copyable
  via Cmd+C / Ctrl+C through the existing OSC 52 + manual handlers.
- `rightClickSelectsWord: true` — right-click highlights the word
  under the pointer. Single-action path on top of the modifier-based
  bypass.

The two options coexist with the existing `macOptionIsMeta: true`
(which only affects keyboard, not mouse). No other code change
needed.

Fixes NousResearch#25720.
Copilot AI review requested due to automatic review settings May 14, 2026 14:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/tui Terminal UI (ui-tui/ + tui_gateway/) javascript Pull requests that update javascript code labels May 14, 2026
@aw0318

aw0318 commented May 14, 2026

Copy link
Copy Markdown

Reporter here, confirmed this fix would resolve my workflow. Thanks @wesleysimplicio !

teknium1 added a commit that referenced this pull request May 17, 2026
…tors

Adds release-note attribution mappings for the contributors from group 5:
- @haran2001 (PR #27070, #27068)
- @ms-alan (PR #26443)
- @godlin-gh (PR #26118)
- @wesleysimplicio (PR #25777, ext-email form)
- @Carry00 (PR #26851)
- @alaamohanad169-ship-it (PR #26036)
- @hawknewton (PR #26294)

(YanzhongSu PR #25879 and flamiinngo PR #27231 already mapped.)
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #27382 — your commit was cherry-picked onto current main as part of a batch salvage of low-risk new-contributor PRs. Authorship preserved (fix(webui): allow native text selection in chat via xterm.js bypass (#25720)). Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) javascript Pull requests that update javascript code P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [WebUI] Cannot select arbitrary text in chat on macOS — xterm.js mouse-events mode blocks selection

5 participants