MCPcopy
hub / github.com/midrender/revideo / moveBelow

Method moveBelow

packages/2d/src/lib/components/Node.ts:889–917  ·  view source on GitHub ↗

* Move the node below the provided node in the parent's layout. * * @remarks * The node will be moved below the provided node and from then on will be * rendered below it. By default, if the node is already positioned lower than * the sibling node, it will not get moved. * * @pa

(node: Node, directlyBelow = false)

Source from the content-addressed store, hash-verified

887 * it is already positioned below the sibling.
888 */
889 public moveBelow(node: Node, directlyBelow = false): this {
890 const parent = this.parent();
891 if (!parent) {
892 return this;
893 }
894
895 if (node.parent() !== parent) {
896 useLogger().error(
897 "Cannot position nodes relative to each other if they don't belong to the same parent.",
898 );
899 return this;
900 }
901
902 const children = parent.children();
903 const ownIndex = children.indexOf(this);
904 const otherIndex = children.indexOf(node);
905
906 if (!directlyBelow && ownIndex < otherIndex) {
907 // Nothing to do if the node is already positioned below the target node.
908 // We could move the node so it's directly below the sibling node, but
909 // that might suddenly move it on top of other nodes. This is likely
910 // not what the user wanted to happen when calling this method.
911 return this;
912 }
913
914 const by = otherIndex - ownIndex - 1;
915
916 return this.move(by);
917 }
918
919 /**
920 * Move the node above the provided node in the parent's layout.

Callers

nothing calls this directly

Calls 3

moveMethod · 0.95
useLoggerFunction · 0.90
errorMethod · 0.45

Tested by

no test coverage detected