moveSelectionUp method Null safety

void moveSelectionUp(
  1. SelectionChangedCause cause
)

Move the current selection up by one line.

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

See also:

Implementation

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

  // If the selection is collapsed at the beginning of the field already, then
  // nothing happens.
  if (selection!.isCollapsed && selection!.extentOffset <= 0.0) {
    return;
  }

  final TextPosition positionAbove = _getTextPositionAbove(selection!.extentOffset);
  late final TextSelection nextSelection;
  if (positionAbove.offset == selection!.extentOffset) {
    nextSelection = selection!.copyWith(baseOffset: 0, extentOffset: 0);
    _wasSelectingVerticallyWithKeyboard = false;
  } else {
    nextSelection = selection!.copyWith(
      baseOffset: positionAbove.offset,
      extentOffset: positionAbove.offset,
    );
    _cursorResetLocation = nextSelection.extentOffset;
  }

  _setSelection(nextSelection, cause);
}