deleteWordHelper function

bool deleteWordHelper(
  1. FluentDocument document, {
  2. required bool forward,
})

Deletes a word in the given direction by creating a temporary selection from the current cursor position to the word boundary, then replacing it with an empty string.

Implementation

bool deleteWordHelper(FluentDocument document, {required bool forward}) {
  final root = document.content;
  final cursor = document.cursor;
  final current = CaretStop(cursor.anchorId, cursor.anchorOffset);
  final result = forward
      ? moveWordRight(root, current,
          stops: document.caretStops, cachedLines: document.logicalLines)
      : moveWordLeft(root, current,
          stops: document.caretStops, cachedLines: document.logicalLines);
  if (result.position == null) return false;
  cursor.focusTo(result.position!.fragmentId, result.position!.offset);
  executeHandleReplaceSelection('', document);
  return true;
}