Skip to content

feat(selection): El::selection_enabled(bool), a subtree or window switch for selectable text - #2206

Merged
opencodejr[bot] merged 1 commit into
devfrom
bot/issue-358
Nov 25, 2026
Merged

opencodejr[bot] merged 1 commit into
devfrom
bot/issue-358

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Closes #358.

Adds El::selection_enabled(on: bool), which turns El::selectable text on or off for a whole subtree. It works like SwiftUI's .textSelection(.disabled). Setting it on the view's root gives one app-wide "Enable text selection" setting.

How it behaves

  • false turns off every El::selectable text in the element and below it: no I-beam, drag, double- or triple-click, Cmd/Ctrl+A, Tx::select_text, Tx::select_all_text or copy. Those texts leave their El::selection_group, and a selection holding one of them clears at the next commit (prune_text_selection).
  • true on a descendant turns selection back on for that subtree, for values meant to be copied.
  • With no setting anywhere, behaviour is the same as before. The switch doesn't make text selectable by itself.

Why a separate builder, not an inherited El::selectable(false) as the issue suggested: message bodies call .selectable(true), and the app switch has to override that. With a single inherited selectable flag there would be no way to tell "this text is copyable" apart from "selection is allowed here". It is named selection_enabled so it doesn't clash with the Tx::text_selection() / Runtime::text_selection() getters.

How it works

  • ElCold gains selection_enabled: Option<bool> and Node gains an inherited selection_off.
  • flatten_node clears TextSpec::selectable on texts in an off subtree. Hit testing, selection, copy, accessibility and paint already read that field.
  • Cursor: El::selectable now records on the text (TextSpec::selectable_cursor) when it was the one that added the I-beam, and only that I-beam is removed. A cursor set with El::cursor stays.
  • Caret browsing: a caret_browsing group in an off subtree doesn't take focus (flatten.rs and is_caret_browsing_node).
  • Memo reuse: InheritedFlatten.selection_off and same_el_cold keep a memo flattened under one setting from being reused under the other.
  • Virtual rows: window_tree, populate_virtual_children, virtual_selection::Scope, remount and selection_collect carry the value, so rows that aren't mounted add no texts from an off subtree.
  • Web pages: text that selects by default doesn't select inside an off subtree (page_text_selects).
  • The API lives in the new el/selection_scope.rs. Files already over the 800-line cap gain only a few lines each, so this doesn't do the separate split-first PR that AGENTS.md asks for before adding to them.
  • Cost: the text is only rewritten when it was selectable. A text built fresh each commit belongs to that commit alone, so turning it off doesn't copy it; only a memo that is flattened again makes one copy, as redacted text already does. No benchmark was run.
  • Changelog: changelog/unreleased/2026-11-25-selection-enabled.md.

Tests: crates/rune/src/runtime/selection_enabled_tests.rs, 12 tests:

  • a default baseline where everything selects;
  • an off subtree: no drag, double-click, Cmd+A, select_all_text or select_text, and no I-beam;
  • a descendant's true opts back in, and its group skips the turned-off texts;
  • switching back on restores selection;
  • a fixed-version memo follows its ancestor's switch both ways;
  • turning it off clears a held selection;
  • only the I-beam selectable added is removed;
  • a caret-browsing group takes no focus;
  • 40 virtual_rows under an off root select nothing, before and after scrolling;
  • with opted-in headers, select-all copies only the headers, including rows that aren't mounted and after a remount;
  • the row collector, called directly.

Not yet built or run: cargo isn't available where this was written, so nothing has been compiled, linted or tested. That needs CI or a local run:

  • cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid
  • cargo check --workspace --all-targets
  • cargo clippy

scripts/file-size.sh passes (no errors, no folders out of shape), and the public-repo hygiene grep is clean. The web-page change has no test.

Closes #358

@opencodejr
opencodejr Bot merged commit 38f8dc5 into dev Nov 25, 2026
1 check passed
Hona added a commit that referenced this pull request Nov 25, 2026
#2206 added a bool (selectable_cursor) to TextSpec, which made it 232 bytes; the compile-time assert on its size (224, the budget of #579) then failed, and rune no longer compiled on any 64-bit target. fade_em, the width of a truncate_fade edge that few texts set, moves behind the cold box; the new flag takes its room. The usual width is the cold block's default, so truncate_fade allocates nothing.
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.

Selection: a window-wide switch for text selection

0 participants