Module selection
Expand description
Shared collection selection models.
SelectionModel is the compact index-based form for immutable local
lists. KeySelection keeps selection attached to stable model keys and
represents select-all as a complement, making it suitable for mutable,
virtualized, and partially resident collections.
Several toolkit widgets surface a list of homogeneous items that the
user can select — DataTable list mode, the file picker, the
file-explorer’s views — and they all need the same selection
semantics, so that logic lives here once instead of being re-derived
(subtly differently) in each widget.
Pure index bookkeeping: it knows nothing about geometry, rendering, or
what the indices point at. Widgets map a click/keystroke to an index and
call SelectionModel::apply_click or SelectionModel::move_to, then
paint is_selected(i) and treat primary() as the keyboard cursor.
§Semantics (matching common file managers)
| Gesture | Effect |
|---|---|
| click | select only i; anchor = primary = i |
| Ctrl+click | toggle i; anchor = primary = i |
| Shift+click | select the inclusive range anchor..=i (replace) |
| Ctrl+Shift+click | add the inclusive range anchor..=i to the set |
| arrow (no mod) | select only the new index |
| Shift+arrow | extend the range from the anchor to the new index |
When there is no anchor yet, Shift gestures degrade to a plain single-select (there is nothing to extend from).
Structs§
- KeySelection
- Stable-key multi-selection for virtualized and mutable collections.
- Selection
Model - Index-based multi-selection state. Indices are opaque
usizes the owning widget assigns to its items (typically the row/cell order).