Skip to content

helix-mode: introduce HelixRange selection type (no wiring)#1061

Open
kronberger-droid wants to merge 1 commit into
nushell:mainfrom
kronberger-droid:helix/range-type
Open

helix-mode: introduce HelixRange selection type (no wiring)#1061
kronberger-droid wants to merge 1 commit into
nushell:mainfrom
kronberger-droid:helix/range-type

Conversation

@kronberger-droid
Copy link
Copy Markdown
Contributor

Summary

Introduces HelixRange, a anchor/head selection range type similar to helix-core, along with a Direction enum. The type has no callers yet and is gated behind #![allow(dead_code)] until future PRs.

Motivation

Part of #960, and follow-up to #1039.

Reedline already has selection state via Editor::selection_anchor plus the insertion point. That model fits vi's visual mode but doesn't carry two things helix needs:

  • Direction: anchor and head are named, not just a min/max pair.
  • Persistence: in helix, every motion produces a selection that survives until the next motion or operator clears it. selection_anchor exists only when the user has actively started a selection in vi.

Rather than retrofit selection_anchor to carry direction, this PR adds a helix-local type that encodes both properties.

Why direction matters

Behaviors that depend on this:

  1. Block cursor placement (one grapheme inside the head edge)
  2. Selection flip — swap the active end without losing the range
  3. Extending motions know which edge to grow when the head moves

What's included

  • HelixRange { anchor, head } with gap-indexing semantics (left-inclusive, right-exclusive, regardless of anchor/head ordering)
  • Pure-integer methods on HelixRange
  • Direction::{Forward, Backward} enum
  • 32 unit tests

What's deliberately deferred

  • Grapheme-aware methods: translate between byte positions and graphemes, and place the visible cursor on the correct side of the selection (future PR).
  • Multi-range Selection: reedline is single line.

Adaptations from helix-core

helix-core reedline Why
RopeSlice &str (future PRs) reedline uses String, not Rope
char indices byte offsets reedline's established convention

Tests

cargo test --features helix --lib edit_mode::helix::range

All 32 tests pass.

The module is pub(super) and gated behind the helix feature flag, thus no behavior change possible.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Apr 27, 2026

This is a pretty small changeset with many tests (thanks). It looks good to me but I'd like to get @schlich's input on it before we land it. Thanks!

@schlich
Copy link
Copy Markdown
Contributor

schlich commented Apr 30, 2026

I'll take a look either tonight or this weekend!

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 4, 2026

@schlich Have you had time to review yet? Sorry to nag.

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.

3 participants