getLineBoundary method

  1. @override
TextRange getLineBoundary(
  1. TextPosition position
)
override

Returns the text range of the line at the given offset.

The newline, if any, is included in the range.

The position parameter must be relative to the node's content.

Valid only after layout.

Implementation

@override
TextRange getLineBoundary(TextPosition position) {
  final lineDy = getOffsetForCaret(position).translate(0, 0.5 * preferredLineHeight(position)).dy;
  final lineBoxes = _getBoxes(TextSelection(baseOffset: 0, extentOffset: line.length - 1))
      .where((element) => element.top < lineDy && element.bottom > lineDy)
      .toList(growable: false);
  return TextRange(
      start: getPositionForOffset(Offset(lineBoxes.first.left, lineDy)).offset,
      end: getPositionForOffset(Offset(lineBoxes.last.right, lineDy)).offset);
}