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

Method moveAbove

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

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

(node: Node, directlyAbove = false)

Source from the content-addressed store, hash-verified

930 * already positioned above the sibling.
931 */
932 public moveAbove(node: Node, directlyAbove = false): this {
933 const parent = this.parent();
934 if (!parent) {
935 return this;
936 }
937
938 if (node.parent() !== parent) {
939 useLogger().error(
940 "Cannot position nodes relative to each other if they don't belong to the same parent.",
941 );
942 return this;
943 }
944
945 const children = parent.children();
946 const ownIndex = children.indexOf(this);
947 const otherIndex = children.indexOf(node);
948
949 if (!directlyAbove && ownIndex > otherIndex) {
950 // Nothing to do if the node is already positioned above the target node.
951 // We could move the node so it's directly above the sibling node, but
952 // that might suddenly move it below other nodes. This is likely not what
953 // the user wanted to happen when calling this method.
954 return this;
955 }
956
957 const by = otherIndex - ownIndex + 1;
958
959 return this.move(by);
960 }
961
962 /**
963 * Change the parent of this node while keeping the absolute transform.

Callers

nothing calls this directly

Calls 3

moveMethod · 0.95
useLoggerFunction · 0.90
errorMethod · 0.45

Tested by

no test coverage detected