fix: avoid moveToTop if node is on top

This commit is contained in:
Gumball12 2021-12-04 00:06:13 +09:00
parent bdcfb2455f
commit 1cb224d7ee
No known key found for this signature in database
GPG Key ID: DA9AA0DC08CAD1E2

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