moveSelectionRightByLine method Null safety

void moveSelectionRightByLine(
  1. SelectionChangedCause cause

Move the current selection to the rightmost point of the current line.

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

See also:


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

  // If already at the right edge of the line, do nothing.
  final TextSelection currentLine = _getLineAtOffset(TextPosition(
    offset: selection!.extentOffset,
  if (currentLine.extentOffset == selection!.extentOffset) {

  // When going right, we want to skip over any whitespace after the line,
  // so we go forward to the first non-whitespace character before asking
  // for the line bounds, since _getLineAtOffset finds the line
  // boundaries without including whitespace (like the newline).
  final int startPoint = nextCharacter(selection!.extentOffset, _plainText, false);
  final TextSelection selectedLine = _getLineAtOffset(TextPosition(offset: startPoint));
  final TextSelection nextSelection = TextSelection.collapsed(
    offset: selectedLine.extentOffset,
    affinity: TextAffinity.upstream,

  _setSelection(nextSelection, cause);