getSelectionRect static method

Rect getSelectionRect(
  1. RenderBox renderBox,
  2. double startGlyphHeight,
  3. double endGlyphHeight,
  4. List<TextSelectionPoint> selectionEndpoints,
)

Returns the Rect covering the given selection in the given RenderBox in global coordinates.

Implementation

static Rect getSelectionRect(
  RenderBox renderBox,
  double startGlyphHeight,
  double endGlyphHeight,
  List<TextSelectionPoint> selectionEndpoints,
) {
  final Rect editingRegion = _getEditingRegion(renderBox);

  if (editingRegion.left.isNaN || editingRegion.top.isNaN
    || editingRegion.right.isNaN || editingRegion.bottom.isNaN) {
    return Rect.zero;
  }

  final bool isMultiline = selectionEndpoints.last.point.dy - selectionEndpoints.first.point.dy >
      endGlyphHeight / 2;

  return Rect.fromLTRB(
    isMultiline
        ? editingRegion.left
        : editingRegion.left + selectionEndpoints.first.point.dx,
    editingRegion.top + selectionEndpoints.first.point.dy - startGlyphHeight,
    isMultiline
        ? editingRegion.right
        : editingRegion.left + selectionEndpoints.last.point.dx,
    editingRegion.top + selectionEndpoints.last.point.dy,
  );
}