executeHandleTextAlign function

bool executeHandleTextAlign(
  1. FluentDocument document,
  2. String align
)

Applies text alignment to Paragraphs in the selection or to the Paragraph under the cursor.

Implementation

bool executeHandleTextAlign(FluentDocument document, String align) {
  final root = document.content;
  final cursor = document.cursor;

  final selection = resolveSelection(
    root,
    cursor.anchorId,
    cursor.anchorOffset,
    cursor.focusId,
    cursor.focusOffset,
    cachedStops: document.caretStops,
    cachedLines: document.logicalLines,
  );

  if (selection != null) {
    for (final node in selection.nodes) {
      _applyToParagraphs(node.container as FNode, align);
    }
    document.pendingTextAlign = align;
    document.updateContent();
    return true;
  }

  // Collapsed cursor: apply to the current Paragraph and update pending.
  final container = findLogicalContainer(root, cursor.anchorId);
  if (container != null) {
    _applyToParagraphs(container as FNode, align);
    document.pendingTextAlign = align;
    document.updateContent();
    return true;
  }

  return false;
}