executeHandleClearFormatting function

bool executeHandleClearFormatting(
  1. FluentDocument document
)

Removes all formatting from the selected text. Keeps only plain text.

Implementation

bool executeHandleClearFormatting(FluentDocument document) {
  document.saveState(description: 'Clear formatting', forceNewAction: true);

  final cursor = document.cursor;

  final selection = resolveSelectionFromCursor(document);

  if (selection != null) {
    return _clearFormattingFromSelection(document, selection);
  }

  if (cursor.isCollapsed) {
    document.pendingStyles = [];
    document.pendingFontFamily = 'DejaVu Sans';
    document.pendingFontSize = 14.0;
    document.pendingColor = null;
    document.pendingHighlightColor = null;
    document.pendingStyle = ParagraphStyle.normal;

    final container = document.findLogicalContainerCached(cursor.anchorId);
    if (container is Paragraph) {
      container.styleName = 'normal';
    }

    document.updateContent();
    return true;
  }

  return false;
}