selectPositionAt method
void
selectPositionAt({
- required Offset from,
- Offset? to,
- required SelectionChangedCause cause,
override
Select text between the global positions from
and to
.
Implementation
@override
void selectPositionAt({
required Offset from,
Offset? to,
required SelectionChangedCause cause,
}) {
// _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
if (onSelectionChanged == null) {
return;
}
final fromPosition = getPositionForOffset(from);
final toPosition = to == null ? null : getPositionForOffset(to);
var baseOffset = fromPosition.offset;
var extentOffset = fromPosition.offset;
if (toPosition != null) {
baseOffset = math.min(fromPosition.offset, toPosition.offset);
extentOffset = math.max(fromPosition.offset, toPosition.offset);
}
final newSelection = TextSelection(
baseOffset: baseOffset,
extentOffset: extentOffset,
affinity: fromPosition.affinity,
);
// Call [onSelectionChanged] only when the selection actually changed.
_handleSelectionChange(newSelection, cause);
}