qwen-code/docs/users/reference
ChiGao 401170d488
feat(cli): mouse text selection and copy in VP mode (#6937)
* docs(cli): design for VP mode mouse text selection and copy

First step of the VP mouse-selection feature: the design doc, submitted
ahead of implementation so the approach can be reviewed before code lands.

Proposes an application-level selection and copy system for VP mode, where
SGR mouse tracking currently suppresses native terminal selection. Evaluates
two routes and commits to exposing the Ink renderer cell grid via the
existing Ink patch, which makes coordinate-to-text mapping uniform across all
content types. Implementation follows as staged milestones on this branch.

* docs(cli): revise VP selection design per feasibility audit

Rework the design after the implementation-feasibility audit against the
Ink 7 renderer source. Key corrections and scope changes:

- Two-PR plan. PR 1 (this branch) delivers the Ink frame-buffer foundation
  and a visible-region visual-selection MVP (visual-cell copy, clear on
  scroll). PR 2 adds cross-screen selection and semantic copy fidelity
  (soft-wrap rejoin, gutter exclusion), which need renderer semantic metadata.
- Highlight goes through a bidirectional frame controller with a
  pre-serialization transform and throttled repaint; the earlier read-only
  accessor plus post-commit callback could not highlight the current frame.
- Immutable cell/style allocation to avoid leaking the highlight onto other
  on-screen occurrences of the same text via shared cached styled chars.
- Corrected coordinate formula (frame is not unconditionally top-anchored),
  OSC 52 behavior (over-cap skips and returns false; surface a copy failure),
  and the note that release already has non-selection consumers.
- Merge gate and milestones aligned to the two-PR split.

* feat(cli): M0 Ink frame-buffer controller for VP text selection

First implementation milestone of VP-mode mouse text selection: the Ink
frame-buffer foundation and its read-side wrapper, with the design's M0
go/no-go criteria proven by tests.

Extend the Ink patch into a small bidirectional frame controller. The
renderer now retains the composited cell grid, applies a selection-range
background highlight before serialization (allocating new cells so the
shared cached styled chars are never mutated), and publishes an immutable
frame each render. setSelection deduplicates and schedules exactly one
repaint through Ink's own throttle; getFrameController(stdout) exposes the
bridge to the application.

Add ScreenBuffer, the read-side wrapper the selection state machine (M1)
will build on: getCellAt / lineText / dimensions plus setSelection and
subscribe. Tests cover addressable cells, wide-character spacer handling,
pre-serialization highlight and clear, no highlight leakage onto identical
on-screen text, and single-frame-per-change dedup (no render loop).

The package.json export additions from the existing patch are preserved.

* feat(cli): M1 mouse text selection with live highlight in VP mode

Turn mouse press/drag/release in the VP history viewport into a text
selection, highlighted live and copied on release.

- SelectionState: anchor/focus model in composited-frame coordinates,
  normalized to reading order, with collapsed/empty queries.
- selection-text: extract the visual text of a range, emitting a wide glyph
  once (skipping its spacer) and trimming per-line trailing padding. B1
  fidelity — visual cells as shown; soft-wrap rejoin and gutter exclusion
  are PR 2.
- selection-coords: map a terminal cell to frame grid coordinates via the
  frame anchor (bottom-pinned on overflow), plus viewport bounds/clamp.
- TextSelectionController: headless controller that subscribes button-level
  mouse events, drives the state machine, highlights the range through the
  frame controller (setSelection), and copies on release. Ignores the
  scrollbar column and presses outside the viewport; clears on any scroll
  (visible-region only in B1).
- VirtualizedList/ScrollableList expose getViewportRect(); MainContent mounts
  the controller in the VP branch.

Copy-failure feedback, key preemption (Esc/Ctrl+Shift+C), streaming/resize
invalidation, and word/line selection follow in M3/M4.

* feat(cli): gate VP text selection behind ui.textSelection settings

Add ui.textSelection.enabled (default true) and ui.textSelection.copyOnSelect
(default true) and wire them into the selection controller: selection is only
active when enabled, and release copies only when copyOnSelect is on. Disabling
enabled leaves the mouse to the terminal for those who prefer it.

* feat(cli): M4 word/line select, selection invalidation, and docs

- Double-click selects a word, triple-click selects a line, driven by a
  multi-click detector in the controller; word/line spans come from the
  composited frame (non-whitespace run / first-to-last-content cell) and are
  copied on select.
- Invalidate the selection when the content scrolls, streams (scrollHeight
  changes), or the terminal resizes (frame height changes / resize event),
  detected via a frame subscription with a baseline captured at selection
  start. Our own highlight renders leave those unchanged, so there is no
  render loop.
- Document mouse selection in the keyboard-shortcuts reference and the
  ui.textSelection settings in the settings reference; refresh the
  useTerminalBuffer description and regenerate the IDE settings schema.

A single click already clears a selection, so Esc-to-clear, the manual
copy keybinding, the footer "copied" toast, and a drag discoverability hint
are deferred follow-ups within this PR.

* fix(cli): drop redundant resize listener in selection controller

Real-terminal testing surfaced a MaxListenersExceededWarning (11 resize
listeners) on startup: the selection controller added a stdout 'resize'
listener on top of the existing ones. A resize reflows content, which changes
the frame/scroll height already watched by the frame subscription, so the
explicit listener was redundant. Remove it to stay under the max-listeners
cap; invalidation on resize still works via the subscription.

* fix(cli): close VP selection review gaps

* refactor(cli): make VP text selection unconditional

* fix(cli): make VP mouse selection usable

* fix(cli): preserve selection in thought blocks

---------

Co-authored-by: 秦奇 <gary.gq@alibaba-inc.com>
Co-authored-by: Shaojin Wen <shaojin.wensj@alibaba-inc.com>
2026-07-17 08:04:07 +00:00
..
_meta.ts feat: refactor docs 2025-12-05 10:51:57 +08:00
keyboard-shortcuts.md feat(cli): mouse text selection and copy in VP mode (#6937) 2026-07-17 08:04:07 +00:00