selectLineAtPosition method

  1. @override
TextSelection selectLineAtPosition(
  1. TextPosition position
)
override

Implementation

@override
TextSelection selectLineAtPosition(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 localLineRange = child.getLineBoundary(localPosition);
  final line = TextRange(
    start: localLineRange.start + nodeOffset,
    end: localLineRange.end + nodeOffset,
  );

  // When long-pressing past the end of the text, we want a collapsed cursor.
  if (position.offset >= line.end) {
    return TextSelection.fromPosition(position);
  }
  return TextSelection(baseOffset: line.start, extentOffset: line.end);
}