Skip to main content

Module selection

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)

GestureEffect
clickselect only i; anchor = primary = i
Ctrl+clicktoggle i; anchor = primary = i
Shift+clickselect the inclusive range anchor..=i (replace)
Ctrl+Shift+clickadd the inclusive range anchor..=i to the set
arrow (no mod)select only the new index
Shift+arrowextend 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.
SelectionModel
Index-based multi-selection state. Indices are opaque usizes the owning widget assigns to its items (typically the row/cell order).