Merge pull request #1246 from Gumball12/fix/Node.moveToTop

fix: avoid moveToTop if node is on top
This commit is contained in:
Anton Lavrenov 2021-12-07 11:09:58 -05:00 committed by GitHub
commit d84e5a7d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1324,11 +1324,15 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
Util.warn('Node has no parent. moveToTop function is ignored.'); Util.warn('Node has no parent. moveToTop function is ignored.');
return false; return false;
} }
var index = this.index; var index = this.index,
this.parent.children.splice(index, 1); len = this.parent.getChildren().length;
this.parent.children.push(this); if (index < len - 1) {
this.parent._setChildrenIndices(); this.parent.children.splice(index, 1);
return true; this.parent.children.push(this);
this.parent._setChildrenIndices();
return true;
}
return false;
} }
/** /**
* move node up * move node up