removeNodeAndReposition function

bool removeNodeAndReposition(
  1. FluentDocument document,
  2. FNode node, {
  3. bool forward = false,
})

Removes node from the tree and repositions the cursor to the adjacent caret stop (previous when forward is false, next when true). Calls document.updateContent and returns true.

Implementation

bool removeNodeAndReposition(
  FluentDocument document,
  FNode node, {
  bool forward = false,
}) {
  if (document.registry.dispatchDeleteNode(document, node)) return true;

  document.saveState(description: 'Delete node', forceNewAction: true);

  final root = document.content;
  final cursor = document.cursor;
  final stop = forward
      ? moveRight(
          root,
          CaretStop(cursor.anchorId, 1),
          stops: document.caretStops,
          cachedLines: document.logicalLines,
        ).position
      : moveLeft(
          root,
          CaretStop(cursor.anchorId, 0),
          stops: document.caretStops,
          cachedLines: document.logicalLines,
        ).position;
  removeNode(root, node);
  if (stop != null) {
    cursor.moveTo(stop.fragmentId, stop.offset);
  }
  document.updateContent();
  return true;
}