fallbackRepositionCursor function

void fallbackRepositionCursor(
  1. FluentDocument document
)

When the cursor still points to a removed fragment, tries moveLeft then moveRight to find the nearest valid caret stop.

Implementation

void fallbackRepositionCursor(FluentDocument document) {
  final root = document.content;
  final cursor = document.cursor;
  final leftStop = moveLeft(
    root,
    CaretStop(cursor.anchorId, cursor.anchorOffset),
    stops: document.caretStops,
    cachedLines: document.logicalLines,
  );
  if (leftStop.position != null) {
    cursor.moveTo(leftStop.position!.fragmentId, leftStop.position!.offset);
    return;
  }
  final rightStop = moveRight(
    root,
    CaretStop(cursor.anchorId, cursor.anchorOffset),
    stops: document.caretStops,
    cachedLines: document.logicalLines,
  );
  if (rightStop.position != null) {
    cursor.moveTo(rightStop.position!.fragmentId, rightStop.position!.offset);
  }
}