textMoveByCharacter function

TextCursorCommandResult textMoveByCharacter({
  1. required TextDocument document,
  2. required TextOffsetStateSnapshot state,
  3. required bool forward,
  4. bool extendSelection = false,
  5. bool clearSelection = false,
})

Implementation

TextCursorCommandResult textMoveByCharacter({
  required TextDocument document,
  required TextOffsetStateSnapshot state,
  required bool forward,
  bool extendSelection = false,
  bool clearSelection = false,
}) {
  final targetOffset = forward
      ? (state.cursorOffset + 1).clamp(0, document.length)
      : (state.cursorOffset - 1).clamp(0, document.length);
  return moveCursorToOffset(
    textLength: document.length,
    cursorOffset: state.cursorOffset,
    selectionBaseOffset: state.selectionBaseOffset,
    selectionExtentOffset: state.selectionExtentOffset,
    targetOffset: targetOffset,
    extendSelection: extendSelection,
    clearSelection: clearSelection,
  );
}