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.