selectWordAtPosition method
Implementation
@override
TextSelection selectWordAtPosition(TextPosition position) {
// assert(
// _textLayoutLastMaxWidth == constraints.maxWidth &&
// _textLayoutLastMinWidth == constraints.minWidth,
// 'Last width ($_textLayoutLastMinWidth, $_textLayoutLastMaxWidth) not the same as max width constraint (${constraints.minWidth}, ${constraints.maxWidth}).');
final child = childAtPosition(position);
final nodeOffset = child.node.offset;
final localPosition = TextPosition(
offset: position.offset - nodeOffset, affinity: position.affinity);
final localWord = child.getWordBoundary(localPosition);
final word = TextRange(
start: localWord.start + nodeOffset,
end: localWord.end + nodeOffset,
);
// When long-pressing past the end of the text, we want a collapsed cursor.
if (position.offset >= word.end) {
return TextSelection.fromPosition(position);
}
return TextSelection(baseOffset: word.start, extentOffset: word.end);
}