moveCaretVertically method

void moveCaretVertically({
  1. required ProseTextLayout textLayout,
  2. required bool expandSelection,
  3. required bool moveUp,
})

Implementation

void moveCaretVertically({
  required ProseTextLayout textLayout,
  required bool expandSelection,
  required bool moveUp,
}) {
  int? newExtent;

  if (moveUp) {
    newExtent = textLayout.getPositionOneLineUp(selection.extent)?.offset;

    // If there is no line above the current selection, move selection
    // to the beginning of the available text.
    newExtent ??= 0;
  } else {
    newExtent = textLayout.getPositionOneLineDown(selection.extent)?.offset;

    // If there is no line below the current selection, move selection
    // to the end of the available text.
    newExtent ??= text.length;
  }

  selection = TextSelection(
    baseOffset: expandSelection ? selection.baseOffset : newExtent,
    extentOffset: newExtent,
  );
}