resolveSelectionFromCursor function

ResolvedSelection? resolveSelectionFromCursor(
  1. FluentDocument document
)

Resolves the current cursor selection using cached stops and lines. Returns null if the cursor is collapsed or the selection is invalid. Caches the result on the document so multiple widgets in the same cursor-change cycle reuse the same ResolvedSelection.

Implementation

ResolvedSelection? resolveSelectionFromCursor(FluentDocument document) {
  final cursor = document.cursor;
  final key = '${cursor.anchorId}:${cursor.anchorOffset}:'
      '${cursor.focusId}:${cursor.focusOffset}';
  if (key == document.cachedSelectionKey) {
    return document.cachedSelection as ResolvedSelection?;
  }
  final result = resolveSelection(
    document.content,
    cursor.anchorId,
    cursor.anchorOffset,
    cursor.focusId,
    cursor.focusOffset,
    cachedStops: document.caretStops,
    cachedLines: document.logicalLines,
    document: document,
  );
  document.cachedSelectionKey = key;
  document.cachedSelection = result;
  return result;
}