expandSelectionLeftByLine method Null safety

void expandSelectionLeftByLine(
  1. SelectionChangedCause cause
)

Expand the current selection to the start of the line.

The selection will never shrink. The upper offset will be expanded to the beginning of its line, and the original order of baseOffset and TextSelection.extentOffset will be preserved.

If selectionEnabled is false, keeps the selection collapsed and moves it left by line.

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

See also:

Implementation

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

  if (!selectionEnabled) {
    return moveSelectionLeftByLine(cause);
  }

  final int firstOffset = math.min(selection!.baseOffset, selection!.extentOffset);
  final int startPoint = previousCharacter(firstOffset, _plainText, false);
  final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));

  late final TextSelection nextSelection;
  if (selection!.extentOffset <= selection!.baseOffset) {
    nextSelection = selection!.copyWith(
      extentOffset: selectedLine.baseOffset,
    );
  } else {
    nextSelection = selection!.copyWith(
      baseOffset: selectedLine.baseOffset,
    );
  }

  _setSelection(nextSelection, cause);
}