updateNode method

Future<void> updateNode(
  1. Selection? selection,
  2. Node nodeBuilder(
    1. Node node
    ), {
  3. Map? selectionExtraInfo,
})

update the node attributes at the given selection.

If the Selection is not passed in, use the current selection.

Implementation

Future<void> updateNode(
  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.updateNode(node, nodeBuilder(node).attributes);
  }

  transaction.afterSelection = transaction.beforeSelection;
  transaction.selectionExtraInfo = selectionExtraInfo;

  return apply(transaction);
}