setSelections method
Activates normalized multi-cursor selections in document coordinates.
The primary range is mirrored to the legacy cursor and selection fields used by rendering and scrolling.
Implementation
void setSelections(TextSelectionSet value) {
final clamped = TextSelectionSet(
value.ranges.map(
(range) => TextSelectionRange.directional(
anchorOffset: range.anchorOffset.clamp(0, length),
activeOffset: range.activeOffset.clamp(0, length),
),
),
primaryOffset: value.primary?.activeOffset.clamp(0, length),
);
_selections = clamped.ranges.length > 1 ? clamped : null;
final primary =
clamped.primary ??
TextSelectionRange(startOffset: cursorOffset, endOffset: cursorOffset);
_applyLineStateSnapshot(
lineSnapshotFromOffsets(
_document,
cursorOffset: primary.activeOffset,
selectionBaseOffset: primary.isCollapsed ? null : primary.anchorOffset,
selectionExtentOffset: primary.isCollapsed
? null
: primary.activeOffset,
),
);
_lastDocumentChange = null;
_syncCoreState();
}