extendSelectionRightByWord method Null safety

void extendSelectionRightByWord(
  1. SelectionChangedCause cause,
  2. [bool includeWhitespace = true,
  3. bool stopAtReversal = false]
)

Extend the current selection to the next end of a word.

The given SelectionChangedCause indicates the cause of this change and will be passed to onSelectionChanged.

By default, includeWhitespace is set to true, meaning that whitespace can be considered a word in itself. If set to false, the selection will be extended past any whitespace and the first word following the whitespace.

The stopAtReversal parameter is false by default, meaning that it's ok for the base and extent to flip their order here. If set to true, then the selection will collapse when it would otherwise reverse its order. A selection that is already collapsed is not affected by this parameter.

See also:

Implementation

void extendSelectionRightByWord(SelectionChangedCause cause, [bool includeWhitespace = true, bool stopAtReversal = false]) {
  assert(selection != null);

  // When the text is obscured, the whole thing is treated as one big word.
  if (obscureText) {
    return _extendSelectionToEnd(cause);
  }

  assert(
    _textLayoutLastMaxWidth == constraints.maxWidth &&
    _textLayoutLastMinWidth == constraints.minWidth,
    'Last width ($_textLayoutLastMinWidth, $_textLayoutLastMaxWidth) not the same as max width constraint (${constraints.minWidth}, ${constraints.maxWidth}).',
  );
  final TextSelection nextSelection = _extendGivenSelectionRightByWord(
    _textPainter,
    selection!,
    includeWhitespace,
    stopAtReversal,
  );
  if (nextSelection == selection) {
    return;
  }
  _setSelection(nextSelection, cause);
}