Repository: motion-canvas/motion-canvas
File: packages/2d/src/components/Node.ts (TypeScript)

Code before:

    if (!directlyBelow && ownIndex < otherIndex) {
      // Nothing to do if the node is already positioned below the target node.
      // We could move the node so it's directly below the sibling node, but
      // that might suddenly move it on top of other nodes. This is likely
      // not what the user wanted to happen when calling this method.
      return this;
    }

    const by = otherIndex - ownIndex - 1;

    return this.move(by);
  }

  /**
   * 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.
   *
   * @param node - The sibling node below which to move.
   * @param directlyAbove - Whether the node should be positioned directly above the
   *                        sibling. When true, will move the node even if it is
   *                        already positioned above the sibling.
   */
  public moveAbove(node: Node, directlyAbove = false): this {
    const parent = this.parent();
    if (!parent) {
      return this;
    }

    if (node.parent() !== parent) {
      useLogger().error(
        "Cannot position nodes relative to each other if they don't belong to the same parent.",
      );
      return this;
    }

    const children = parent.children();
    const ownIndex = children.indexOf(this);
    const otherIndex = children.indexOf(node);

    if (!directlyAbove && ownIndex > otherIndex) {
      // Nothing to do if the node is already positioned above the target node.
      // We could move the node so it's directly above the sibling node, but
      // that might suddenly move it below other nodes. This is likely not what
      // the user wanted to happen when calling this method.
      return this;
    }

Review comment (suggestion):
```suggestion
   * 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.
   *
   * @param node - The sibling node below which to move.
   * @param directlyAbove - Whether the node should be positioned directly above 
   *                        the sibling. When true, will move the node even if 
   *                        it is already positioned above the sibling.
```

Code after:

    if (!directlyBelow && ownIndex < otherIndex) {
      // Nothing to do if the node is already positioned below the target node.
      // We could move the node so it's directly below the sibling node, but
      // that might suddenly move it on top of other nodes. This is likely
      // not what the user wanted to happen when calling this method.
      return this;
    }

    const by = otherIndex - ownIndex - 1;

    return this.move(by);
  }

  /**
   * 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.
   *
   * @param node - The sibling node below which to move.
   * @param directlyAbove - Whether the node should be positioned directly above the
   *                        sibling. When true, will move the node even if it is
   *                        already positioned above the sibling.
   */
  public moveAbove(node: Node, directlyAbove = false): this {
    const parent = this.parent();
    if (!parent) {
      return this;
    }

    if (node.parent() !== parent) {
      useLogger().error(
        "Cannot position nodes relative to each other if they don't belong to the same parent.",
      );
      return this;
    }

    const children = parent.children();
    const ownIndex = children.indexOf(this);
    const otherIndex = children.indexOf(node);

    if (!directlyAbove && ownIndex > otherIndex) {
      // Nothing to do if the node is already positioned above the target node.
      // We could move the node so it's directly above the sibling node, but
      // that might suddenly move it below other nodes. This is likely not what
      // the user wanted to happen when calling this method.
      return this;
    }