executeHandleParagraphStyle function
Applies a paragraph style to the current paragraph or selection. The style works as a "base" - explicit fragment customizations always take precedence.
Implementation
bool executeHandleParagraphStyle(
FluentDocument document,
ParagraphStyle style,
) {
// Save state for undo/redo
document.saveState(description: 'Change paragraph style to ${style.name}');
final root = document.content;
final cursor = document.cursor;
// If there's a selection, apply it to all paragraphs in the selection
if (!cursor.isCollapsed) {
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) {
final container = node.container;
if (container is Paragraph) {
_applyStyleToParagraph(container, style);
}
}
}
} else {
// Collapsed cursor: apply to the current paragraph
final container = findLogicalContainer(root, cursor.anchorId);
if (container is Paragraph) {
_applyStyleToParagraph(container, style);
} else {
// If we're not in a paragraph, only set the pending style
document.pendingStyle = style;
document.updateContent();
return true;
}
}
// Update the pending style
document.pendingStyle = style;
document.syncPendingFontWithCursor();
document.updateContent();
return true;
}