gpui-base: Add TextSelection for window-level text selection (#2730)
## Summary - add renderer-neutral, window-level text selection to `gpui-base` - migrate `TextView` to the shared selection engine while preserving rich-text parsing, source copy, virtualization, focus, and scrolling behavior - isolate background, Dialog, and Sheet selection with opaque per-window scopes - keep the existing `gpui-component` selection methods as deprecated forwarding shims - add a selectable-text showcase, integration documentation, and lifecycle/compatibility coverage - correct the release workflow to publish the renamed `gpui-base` crate ## API design The public API separates window coordination from renderer-owned state: - `TextSelectionLayer` is mounted once per window and retains the window selection state and pointer handlers. - `TextSelection` provides window-level query and control operations: `selected_text`, `has_selection`, `clear`, `end`, and `activate_scope`. - `TextSelectionHandle` is retained by each selectable participant and owns its snapshot, callbacks, local-selection state, and plain-text projection. - `TextSelectionRegistration` reports per-frame geometry, document order, scroll offset, and scope. - `TextSelectionRun` and `TextSelectionProjection` provide UTF-8-safe range projection for ordinary laid-out text. - `TextSelectionSnapshot`, `TextSelectionEndpoint`, `TextSelectionCoverage`, and `TextSelectionContentKey` support custom and virtualized renderers without exposing internal window state. - `ElementExt::text_selection_scope` marks modal or otherwise isolated subtrees. The engine keeps participant identity stable, uses explicit logical ordering instead of paint or map order, stores endpoints in participant-relative content coordinates, expires registrations by frame, and keeps window registries weak so closed windows release their selection state. ## Compatibility Existing `TextView` behavior remains covered for click/drag and Shift extension, multi-click word/line selection, cross-participant copy, plain/source formats, virtualized blocks, focus, auto-scroll, drag-and-drop suppression, layout changes, modal scopes, and multi-window cleanup. Applications using `gpui_component::Root` receive the `TextSelectionLayer` automatically. The former `Root` and `WindowExt` selection methods remain available as deprecated synchronous forwards to the single base-owned state. ## Verification - `cargo test -p gpui-base text_selection` — 43 passed - `cargo test --workspace --all-targets` — passed - `cargo check --workspace --all-targets` — passed - `cargo clippy --workspace --all-targets -- --deny warnings` — passed - `cargo fmt --all -- --check` — passed - `git diff --check` — passed - `bun run build` in `website` — passed ## Status Kept as draft for maintainer API review. --------- Co-authored-by: Codex <codex@openai.com>
J
Jason Lee committed
fd3bc2bbb8a2c4dfe268c1475682476ada54cd0c
Parent: 000114a
Committed by GitHub <noreply@github.com>
on 8/16/2026, 5:25:29 AM