extendTo method

TextSelection extendTo(
  1. TextPosition position
)

Keeping the selection's TextSelection.baseOffset fixed, pivot the TextSelection.extentOffset to the given TextPosition.

In some cases, the TextSelection.baseOffset and TextSelection.extentOffset may flip during this operation, and/or the size of the selection may shrink.

Difference with expandTo

In contrast with this method, expandTo is strictly growth; the selection is grown to include the given TextPosition and will never shrink.

Implementation

TextSelection extendTo(TextPosition position) {
  // If the selection's extent is at the position already, then nothing
  // happens.
  if (extent == position) {
    return this;
  }

  return copyWith(
    extentOffset: position.offset,
    affinity: position.affinity,
  );
}