pressRightArrowKey method

void pressRightArrowKey({
  1. bool isShiftPressed = false,
})

Moves the cursor one character to the right.

If isShiftPressed is true, extends the selection.

Implementation

void pressRightArrowKey({bool isShiftPressed = false}) {
  int newOffset;
  if (!isShiftPressed && selection.start != selection.end) {
    newOffset = selection.end;
  } else if (selection.extentOffset < length) {
    newOffset = selection.extentOffset + 1;
  } else {
    newOffset = length;
  }

  if (isShiftPressed) {
    setSelectionSilently(
      TextSelection(
        baseOffset: selection.baseOffset,
        extentOffset: newOffset,
      ),
    );
  } else {
    setSelectionSilently(TextSelection.collapsed(offset: newOffset));
  }
}