formatNode method
format the node at the given selection.
If the Selection is not passed in, use the current selection.
Implementation
Future<void> formatNode(
Selection? selection,
Node Function(
Node node,
) nodeBuilder, {
Map? selectionExtraInfo,
}) async {
selection ??= this.selection;
selection = selection?.normalized;
if (selection == null) {
return;
}
final nodes = getNodesInSelection(selection);
if (nodes.isEmpty) {
return;
}
final transaction = this.transaction;
for (final node in nodes) {
transaction
..insertNode(
node.path,
nodeBuilder(node),
)
..deleteNode(node)
..afterSelection = transaction.beforeSelection
..selectionExtraInfo = selectionExtraInfo;
}
return apply(transaction);
}