moveSelectionDown method Null safety

void moveSelectionDown(
  1. SelectionChangedCause cause
)

Move the current selection to the next line.

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

See also:

Implementation

void moveSelectionDown(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;
  }

  final TextPosition positionBelow = _getTextPositionBelow(selection!.extentOffset);

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

  _setSelection(nextSelection, cause);
}