Selection
rs-grid uses an anchor/focus selection model. The anchor is where the selection started; the focus is where it currently ends. Shift-click extends the selection from the anchor to a new focus.
SelectionState
SelectionState tracks two positions:
Each position can refer to a cell, a row, or a column. Mixed granularity (anchor on a cell, focus on a row) is not supported.
Commands
Hit-testing
Given a pixel coordinate (x, y) relative to the canvas, hit-testing returns
the cell under the cursor:
Hit-testing uses the same precomputed column offset array as the viewport, giving O(log n) performance. Row hit-testing is O(1) with uniform row height.
Never introduce an O(n) scan in the hit-testing path. The O(log n) guarantee is a core invariant.
Rendering the selection
SceneBuilder reads SelectionState and emits ScenePrimitive::Rect entries
with the selection highlight color for every selected cell in the viewport.
Even with a full-grid selection (all rows x all columns), only the primitives for visible cells are built. The scene size is bounded by the viewport, not the selection size.
Row-selection checkbox column
Separate from the anchor/focus selection above, rs-grid supports an opt-in row-selection checkbox column, with a per-row checkbox and a tri-state header checkbox ("select all"). Unlike the row-number gutter, it is not a fixed/pinned band — it's the first column of the scrollable region, so it scrolls away with the data on horizontal scroll, just like a regular column.
Checked state is tracked separately from SelectionState, by physical
row id (not display position), so it survives sorting and filtering:
CheckboxTriState (Checked / Unchecked / Indeterminate) describes the
header checkbox's state — Indeterminate when some but not all rows in
scope are checked. Clicking an indeterminate header checks every row in
scope rather than unchecking them.
On GridCanvas (the browser integration):
"Select all" only affects rows passing the active filter, not the entire dataset — checking rows hidden by a filter would be surprising for a subsequent bulk action (matches the convention used by most data-grid libraries).

