executeHandleClearFormatting function
Removes all formatting from the selected text. Keeps only plain text.
Implementation
bool executeHandleClearFormatting(FluentDocument document) {
document.saveState(description: 'Clear formatting', forceNewAction: true);
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) {
return _clearFormattingFromSelection(document, selection);
}
// Collapsed cursor: reset pending styles and style
if (cursor.isCollapsed) {
document.pendingStyles = [];
document.pendingFontFamily = 'Arial';
document.pendingFontSize = 14.0;
document.pendingColor = null;
document.pendingHighlightColor = null;
document.pendingStyle = ParagraphStyle.normal;
// Also reset the current paragraph style to "normal"
final container = findLogicalContainer(root, cursor.anchorId);
if (container is Paragraph) {
container.styleName = 'normal';
}
document.updateContent();
return true;
}
return false;
}