Skip to content

input: Add InputState::add_selection for programmatic multi-cursor - #3403

Merged
huacnlee merged 2 commits into
longbridge:mainfrom
sola-ryu:input-add-selection
Oct 8, 2026
Merged

huacnlee merged 2 commits into
longbridge:mainfrom
sola-ryu:input-add-selection

Conversation

@sola-ryu

@sola-ryu sola-ryu commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Multi-cursor editing exists internally (Alt-click, the AddCursorAbove/Below actions), but applications had no public API to place a cursor at an arbitrary byte range. That makes features like "select all occurrences" (VS Code's Cmd+Shift+L) or additive "select next occurrence" impossible to build on top of the editor.

This change adds a single public method, InputBaseState::add_selection, the programmatic equivalent of Alt-clicking another cursor into the text.

Behavior mirrors the existing internal paths:

  • The range is clipped to the text and expanded to character boundaries, like set_selected_range.
  • A range already covered by a selection adds nothing (Alt-click is idempotent the same way).
  • On a single-line input there is no second cursor, so the call falls back to replacing the selection.
  • The view scrolls to the new selection, matching set_selected_range via move_to.

Public API

gpui-base

  • InputBaseState::add_selection(&mut self, range: Range<usize>, cx: &mut Context<Self>) — Adds range as an additional selection while keeping existing ones, enabling programmatic multi-cursor placement (e.g. select-all-occurrences).

This PR is 100% AI-generated, reviewed and validated by the contributor: cargo fmt --check, cargo clippy -p gpui-base --all-targets -- --deny warnings, and the input test suite (329 passed, including the new test_add_selection) are all green.

@huacnlee
huacnlee enabled auto-merge (squash) October 8, 2026 03:08
@huacnlee
huacnlee merged commit c7b5b48 into longbridge:main Oct 8, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants