gpui-base: Add TextSelection for window-level text selection - #2730
Merged
Conversation
huacnlee
marked this pull request as ready for review
August 16, 2026 04:59
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
huacnlee
force-pushed
the
text-selection-base-architecture
branch
from
August 16, 2026 05:09
f3db395 to
99a9af2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gpui-baseTextViewto the shared selection engine while preserving rich-text parsing, source copy, virtualization, focus, and scrolling behaviorgpui-componentselection methods as deprecated forwarding shimsgpui-basecrateAPI design
The public API separates window coordination from renderer-owned state:
TextSelectionLayeris mounted once per window and retains the window selection state and pointer handlers.TextSelectionprovides window-level query and control operations:selected_text,has_selection,clear,end, andactivate_scope.TextSelectionHandleis retained by each selectable participant and owns its snapshot, callbacks, local-selection state, and plain-text projection.TextSelectionRegistrationreports per-frame geometry, document order, scroll offset, and scope.TextSelectionRunandTextSelectionProjectionprovide UTF-8-safe range projection for ordinary laid-out text.TextSelectionSnapshot,TextSelectionEndpoint,TextSelectionCoverage, andTextSelectionContentKeysupport custom and virtualized renderers without exposing internal window state.ElementExt::text_selection_scopemarks 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
TextViewbehavior 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::Rootreceive theTextSelectionLayerautomatically. The formerRootandWindowExtselection methods remain available as deprecated synchronous forwards to the single base-owned state.Verification
cargo test -p gpui-base text_selection— 43 passedcargo test --workspace --all-targets— passedcargo check --workspace --all-targets— passedcargo clippy --workspace --all-targets -- --deny warnings— passedcargo fmt --all -- --check— passedgit diff --check— passedbun run buildinwebsite— passedStatus
Kept as draft for maintainer API review.