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