expandSelectionRightByLine method Null safety

void expandSelectionRightByLine(
  1. SelectionChangedCause cause
)

Expand the current selection to the end of the line.

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

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 expandSelectionRightByLine(SelectionChangedCause cause) {
  assert(selection != null);

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

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

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

  _setSelection(nextSelection, cause);
}