extendSelectionUp method Null safety

void extendSelectionUp(
  1. SelectionChangedCause cause
)

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

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

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

See also:

Implementation

void extendSelectionUp(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;
  }
  if (!selectionEnabled) {
    return moveSelectionUp(cause);
  }

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

  _setSelection(nextSelection, cause);
}