getEndpointsForSelection method

List<TextSelectionPoint> getEndpointsForSelection (
  1. TextSelection selection

Returns the local coordinates of the endpoints of the given selection.

If the selection is collapsed (and therefore occupies a single point), the returned list is of length one. Otherwise, the selection is not collapsed and the returned list is of length two. In this case, however, the two points might actually be co-located (e.g., because of a bidirectional selection that contains some text but whose ends meet in the middle).

See also:


List<TextSelectionPoint> getEndpointsForSelection(TextSelection selection) {
  assert(constraints != null);
  _layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);

  final Offset paintOffset = _paintOffset;

  final List<ui.TextBox> boxes = selection.isCollapsed ?
      <ui.TextBox>[] : _textPainter.getBoxesForSelection(selection);
  if (boxes.isEmpty) {
    // TODO(mpcomplete): This doesn't work well at an RTL/LTR boundary.
    final Offset caretOffset = _textPainter.getOffsetForCaret(selection.extent, _caretPrototype);
    final Offset start = Offset(0.0, preferredLineHeight) + caretOffset + paintOffset;
    return <TextSelectionPoint>[TextSelectionPoint(start, null)];
  } else {
    final Offset start = Offset(boxes.first.start, boxes.first.bottom) + paintOffset;
    final Offset end = Offset(boxes.last.end, boxes.last.bottom) + paintOffset;
    return <TextSelectionPoint>[
      TextSelectionPoint(start, boxes.first.direction),
      TextSelectionPoint(end, boxes.last.direction),