Skip to main content

Module keyed_selection_model

Module keyed_selection_model 

Source
Expand description

KeyedSelectionModel<K> — identity-based selection for collection widgets.

KeyedSelectionModel<K> stores selection as a set of source-defined keys rather than visible indices. This is what SelectionModel cannot do: survive lazy window-slides and external reorders, and stay consistent across two views of the same source that scroll/sort/filter independently (selection is a set of identities, not positions). It coexists with the index-based SelectionModel — views opt into one or the other.

Shift+click range extension is index-ordered by nature, so extend_to takes the current visible key order from the caller (the projection) at click time; the anchor is stored as a key so it survives scrolling out of the resident window. The selection is exposed as a reactive Signal<HashSet<K>> via selection_signal().

§When to use

Use KeyedSelectionModel when rows are identified by a stable domain key (entity id, file path, UUID) that survives reorders, sorts, and lazy-loading evictions. Use SelectionModel when rows are identified by their current visible index (simple in-memory lists).

let sel: KeyedSelectionModel<u64> = KeyedSelectionModel::new(SelectionMode::Multi);
sel.select(10);
sel.toggle(20);
sel.toggle(30);
assert_eq!(sel.count(), 3);
sel.toggle(10); // deselect
assert!(!sel.is_selected(&10));
sel.clear();
assert_eq!(sel.count(), 0);

Structs§

KeyedSelectionModel
Selection state keyed by source-defined identity rather than visible index.