getBaseEndpointForSelection method

  1. @override
TextSelectionPoint getBaseEndpointForSelection(
  1. TextSelection selection
)
override

Returns a list of rects that bound the given selection.

A given selection might have more than one rect if this text painter contains bidirectional text because logically contiguous text might not be visually contiguous.

Valid only after layout. Returns a point for the base selection handle used on touch-oriented devices.

The selection parameter is expected to be in local offsets to this render object's node.

Implementation

@override
TextSelectionPoint getBaseEndpointForSelection(TextSelection selection) {
  if (selection.isCollapsed) {
    return TextSelectionPoint(
        Offset(0, preferredLineHeight(selection.extent)) +
            getOffsetForCaret(selection.extent),
        null);
  }

  final baseNode = getContainer().queryChild(selection.start, false).node;
  var baseChild = firstChild;
  while (baseChild != null) {
    if (baseChild.getContainer() == baseNode) {
      break;
    }
    baseChild = childAfter(baseChild);
  }
  assert(baseChild != null);

  final basePoint = baseChild!.getBaseEndpointForSelection(
      localSelection(baseChild.getContainer(), selection, true));
  return TextSelectionPoint(
      basePoint.point + (baseChild.parentData as BoxParentData).offset,
      basePoint.direction);
}