From 1cb224d7eef6ac78225a6c524bd73237b3443ccf Mon Sep 17 00:00:00 2001 From: Gumball12 Date: Sat, 4 Dec 2021 00:06:13 +0900 Subject: [PATCH] fix: avoid moveToTop if node is on top --- src/Node.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Node.ts b/src/Node.ts index 21718a39..86300cfc 100644 --- a/src/Node.ts +++ b/src/Node.ts @@ -1324,11 +1324,15 @@ export abstract class Node { 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