insert method

bool insert(
  1. Path path,
  2. Iterable<Node> nodes
)

Inserts a Nodes at the given Path.

Implementation

bool insert(Path path, Iterable<Node> nodes) {
  if (path.isEmpty || nodes.isEmpty) {
    return false;
  }

  final target = nodeAtPath(path);
  if (target != null) {
    for (final node in nodes) {
      target.insertBefore(node);
    }
    return true;
  }

  final parent = nodeAtPath(path.parent);
  if (parent != null) {
    for (var i = 0; i < nodes.length; i++) {
      parent.insert(nodes.elementAt(i), index: path.last + i);
    }
    return true;
  }

  return false;
}