setSelectionRange method

void setSelectionRange(
  1. String? anchorFragmentId,
  2. int? anchorLocalOffset,
  3. String? focusFragmentId,
  4. int? focusLocalOffset,
)

Implementation

void setSelectionRange(
  String? anchorFragmentId,
  int? anchorLocalOffset,
  String? focusFragmentId,
  int? focusLocalOffset,
) {
  // Skip repaint when the range is identical — crucial during key-hold
  // where _syncSelectionManager touches every visible paragraph but
  // only a few actually changed.
  if (_selAnchorFragmentId == anchorFragmentId &&
      _selAnchorLocalOffset == anchorLocalOffset &&
      _selFocusFragmentId == focusFragmentId &&
      _selFocusLocalOffset == focusLocalOffset) {
    return;
  }
  _selAnchorFragmentId = anchorFragmentId;
  _selAnchorLocalOffset = anchorLocalOffset;
  _selFocusFragmentId = focusFragmentId;
  _selFocusLocalOffset = focusLocalOffset;
  _cachedSelectionBoxes = null; // invalidate paint cache
  markNeedsPaint();
}