extendSelectionDown method Null safety

void extendSelectionDown(
  1. SelectionChangedCause cause
)

Keeping selection's TextSelection.baseOffset fixed, move the TextSelection.extentOffset down by one line.

If selectionEnabled is false, keeps the selection collapsed and just moves it down.

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

See also:

Implementation

void extendSelectionDown(SelectionChangedCause cause) {
  assert(selection != null);

  // If the selection is collapsed at the end of the field already, then
  // nothing happens.
  if (selection!.isCollapsed && selection!.extentOffset >= _plainText.length) {
    return;
  }
  if (!selectionEnabled) {
    return moveSelectionDown(cause);
  }

  final TextPosition positionBelow = _getTextPositionBelow(selection!.extentOffset);
  late final TextSelection nextSelection;
  if (positionBelow.offset == selection!.extentOffset) {
    nextSelection = selection!.copyWith(
      extentOffset: _plainText.length,
    );
    _wasSelectingVerticallyWithKeyboard = true;
  } else if (_wasSelectingVerticallyWithKeyboard) {
    nextSelection = selection!.copyWith(
      extentOffset: _cursorResetLocation,
    );
    _wasSelectingVerticallyWithKeyboard = false;
  } else {
    nextSelection = selection!.copyWith(
      extentOffset: positionBelow.offset,
    );
    _cursorResetLocation = nextSelection.extentOffset;
  }

  _setSelection(nextSelection, cause);
}