[Tree] Fix error when removing child from `Tree`
New `last_child` member was not properly updated
This commit is contained in:
parent
108c603f91
commit
cd4221c1e2
|
@ -178,6 +178,9 @@ private:
|
||||||
if (parent->first_child == this) {
|
if (parent->first_child == this) {
|
||||||
parent->first_child = next;
|
parent->first_child = next;
|
||||||
}
|
}
|
||||||
|
if (parent->last_child == this) {
|
||||||
|
parent->last_child = prev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,30 @@ TEST_CASE("[SceneTree][Tree]") {
|
||||||
memdelete(tree);
|
memdelete(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/godotengine/godot/issues/96205
|
||||||
|
SUBCASE("[Tree] Get last item after removal.") {
|
||||||
|
Tree *tree = memnew(Tree);
|
||||||
|
TreeItem *root = tree->create_item();
|
||||||
|
|
||||||
|
TreeItem *child1 = tree->create_item(root);
|
||||||
|
TreeItem *child2 = tree->create_item(root);
|
||||||
|
|
||||||
|
CHECK_EQ(root->get_child_count(), 2);
|
||||||
|
CHECK_EQ(tree->get_last_item(), child2);
|
||||||
|
|
||||||
|
root->remove_child(child2);
|
||||||
|
|
||||||
|
CHECK_EQ(root->get_child_count(), 1);
|
||||||
|
CHECK_EQ(tree->get_last_item(), child1);
|
||||||
|
|
||||||
|
root->add_child(child2);
|
||||||
|
|
||||||
|
CHECK_EQ(root->get_child_count(), 2);
|
||||||
|
CHECK_EQ(tree->get_last_item(), child2);
|
||||||
|
|
||||||
|
memdelete(tree);
|
||||||
|
}
|
||||||
|
|
||||||
SUBCASE("[Tree] Previous and Next items.") {
|
SUBCASE("[Tree] Previous and Next items.") {
|
||||||
Tree *tree = memnew(Tree);
|
Tree *tree = memnew(Tree);
|
||||||
TreeItem *root = tree->create_item();
|
TreeItem *root = tree->create_item();
|
||||||
|
|
Loading…
Reference in New Issue