Skip to main content

Module selection

Module selection 

Source
Expand description

Host-side selection helpers.

The editor holds no selection state. It reports gestures — a node or link was clicked, the background was clicked, a marquee was released — and renders the selected flag it finds on the rows of your models. Everything between those two ends is the host’s, and this module is what the host needs to do it:

  • resolve_click and resolve_box hold the policy: what a click, a shift-click, a marquee and a shift-marquee mean. They are pure — no storage, no interior mutability — so the host is free to keep the selection wherever it already keeps its state.
  • project_selection writes a selection back into the rows, and selected_rows reads it back out, so a host that wants no separate store can let the rows be the selection.

§Contract

Every intent resolves to an absolute set: the resolvers take the current selection and return the new one in full, never a delta. There is no “add” or “remove” call, and no reachable state in which a selection was half-applied.

§Order

Both resolvers are order-stable: surviving members keep their relative order and new members are appended. Order is presentation-stable and semantically meaningless — it is what an introspecting client sees, and nothing may interpret it. If you ever need a distinguished member (a paste anchor, a “primary” selection), that is an explicit concept to add, never a position in this vector.

Functions§

apply_box
Apply a released marquee to a model whose rows carry the selection.
apply_click
Apply a click to a model whose rows carry the selection.
clear_selection
Deselect every row of a model.
project_selection
Project a selection into a model’s per-row selected flag.
resolve_box
Resolve a released marquee against the current selection.
resolve_click
Resolve a click on item against the current selection.
selected_rows
Collect a key for every row the model currently shows as selected.