function splitTreeAtNest(tree, nest) {
    const grandparent = nth(nest, -3) || tree;
    const parent = nth(nest, -2);
    const node = last(nest);

    const splitIndex = grandparent.children.indexOf(parent);
    const splitChildren = grandparent.children;
    const splitChildIndex = parent.children.indexOf(node);

    const childrenBefore = parent.children.slice(0, splitChildIndex);
    const childrenAfter = parent.children.slice(splitChildIndex + 1);
    const nodeBefore = !isEmpty(childrenBefore) && { ...parent, children: childrenBefore };
    const nodeAfter = !isEmpty(childrenAfter) && { ...parent, children: childrenAfter };

    const childrenToInsert = [nodeBefore, node, nodeAfter].filter(val => !isEmpty(val));
    const beforeChildren = splitChildren.slice(0, splitIndex);
    const afterChildren = splitChildren.slice(splitIndex + 1);
    const newChildren = concat(beforeChildren, childrenToInsert, afterChildren);
    grandparent.children = newChildren;
  }
Node types that can contain "block" nodes as direct children. We check