extendSelectionRightByLine method Null safety

void extendSelectionRightByLine(
  1. SelectionChangedCause cause
)

Extend the current selection to the end of TextSelection.extentOffset's line.

Uses TextSelection.baseOffset as a pivot point and doesn't change it. If TextSelection.extentOffset is left of TextSelection.baseOffset, then collapses the selection.

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

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

See also:

Implementation

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

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

  final int startPoint = nextCharacter(selection!.extentOffset, _plainText, false);
  final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));

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

  _setSelection(nextSelection, cause);
}