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.');
return false;
}
var index = this.index;
this.parent.children.splice(index, 1);
this.parent.children.push(this);
this.parent._setChildrenIndices();
return true;
var index = this.index,
len = this.parent.getChildren().length;
if (index < len - 1) {
this.parent.children.splice(index, 1);
this.parent.children.push(this);
this.parent._setChildrenIndices();
return true;
}
return false;
}
/**
* move node up