getLineBoundsAtOffset method

({String endFrag, int endOff, String startFrag, int startOff})? getLineBoundsAtOffset(
  1. Offset offset
)

Returns the fragment-local start/end bounds of the text line that contains offset (in paragraph-local coordinates). Used by triple-tap to select an entire logical line in O(log n) without rebuilding the whole document tree.

Implementation

({String startFrag, int startOff, String endFrag, int endOff})?
    getLineBoundsAtOffset(Offset offset) {
  final adjustedOffset = offset - Offset(_alignmentXOffset, 0);
  final textPosition = _painter.getPositionForOffset(adjustedOffset);
  final lineBoundary = _painter.getLineBoundary(textPosition);

  final startLocal = _globalToLocal(lineBoundary.start);
  if (startLocal == null) return null;
  final endLocal = _globalToLocal(lineBoundary.end);
  if (endLocal == null) return null;

  return (
    startFrag: startLocal.fragmentId,
    startOff: startLocal.localOffset,
    endFrag: endLocal.fragmentId,
    endOff: endLocal.localOffset,
  );
}