@jsvision/datagrid / selectRange
Function: selectRange()
selectRange(
current,anchorKey,toKey,displayKeys,mode):ReadonlySet<Key>
Defined in: datagrid/src/selection.ts:92
Select the contiguous run between anchorKey and toKey in display order, returning a new set.
The run is the slice of displayKeys between the two keys' positions, inclusive, and is order-independent — an anchor after the target selects the same rows. In multi mode the run is unioned onto current; in single mode it collapses to just {toKey} (a single selection cannot hold a range). If either key is absent from displayKeys (a stale anchor after a delete/filter, or an off-display target), the op degrades to selecting just toKey (unioned onto current in multi).
Parameters
current
ReadonlySet<Key>
The current selection (not mutated).
anchorKey
The range's fixed end (typically the last cursor/selection anchor).
toKey
The range's moving end (the just-picked row).
displayKeys
readonly Key[]
The current display order mapped to keys (display() through rowKey).
mode
'single' (collapses to {toKey}) or 'multi' (unions the run onto current).
Returns
ReadonlySet<Key>
A new selection set extended by the display-order run (or just toKey when stale).
Example
import { selectRange } from '@jsvision/datagrid';
const display = ['a', 'b', 'c', 'd'];
selectRange(new Set(), 'a', 'c', display, 'multi'); // {a, b, c}
selectRange(new Set(), 'c', 'a', display, 'multi'); // {a, b, c} — order-independent
selectRange(new Set(), 'a', 'c', display, 'single'); // {c} — single can't hold a range