浏览代码

Stop move_to_bottom losing references to treeitems

MillionOstrich 8 年之前
父节点
当前提交
8d8a90daef
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      scene/gui/tree.cpp

+ 10 - 7
scene/gui/tree.cpp

@@ -47,18 +47,21 @@ void TreeItem::move_to_top() {
 }
 }
 
 
 void TreeItem::move_to_bottom() {
 void TreeItem::move_to_bottom() {
-
 	if (!parent || !next)
 	if (!parent || !next)
 		return;
 		return;
 
 
-	while (next) {
+	TreeItem *prev = get_prev();
+	TreeItem *last = next;
+	while (last->next)
+		last = last->next;
 
 
-		if (parent->childs == this)
-			parent->childs = next;
-		TreeItem *n = next;
-		next = n->next;
-		n->next = this;
+	if (prev) {
+		prev->next = next;
+	} else {
+		parent->childs = next;
 	}
 	}
+	last->next = this;
+	next = NULL;
 }
 }
 
 
 Size2 TreeItem::Cell::get_icon_size() const {
 Size2 TreeItem::Cell::get_icon_size() const {