getTrailingTextBoundaryAt method

  1. @override
int? getTrailingTextBoundaryAt(
  1. int position
)
override

Returns the int representing the end position of the paragraph that bounds the given position. The returned int is the position of the code unit representing the trailing line terminator that encloses the desired paragraph.

Implementation

@override
int? getTrailingTextBoundaryAt(int position) {
  if (position >= _text.length || _text.isEmpty) {
    return null;
  }

  if (position < 0) {
    return 0;
  }

  int index = position;

  while (!TextLayoutMetrics.isLineTerminator(_text.codeUnitAt(index))) {
    index += 1;
    if (index == _text.length) {
      return index;
    }
  }

  return index < _text.length - 1
              && _text.codeUnitAt(index) == 0x0D
              && _text.codeUnitAt(index + 1) == 0x0A
              ? index + 2
              : index + 1;
}