Fixing TreeItem get_prev_xxx methods when p_wrap is true

Fixes #85032

The code that fix the issue is courtesy of @Jesusemora, I just added
unit tests for it and did a rebase with the latest changes on master.

Co-authored-by: Jesusemora <32273722+Jesusemora@users.noreply.github.com>
This commit is contained in:
Pablo Andres Fuente
2024-09-18 14:01:10 -03:00
parent 694d3c2930
commit 9c0afbb15c
2 changed files with 135 additions and 11 deletions

View File

@@ -923,19 +923,17 @@ TreeItem *TreeItem::_get_prev_in_tree(bool p_wrap, bool p_include_invisible) {
if (!prev_item) {
current = current->parent;
if (current == tree->root && tree->hide_root) {
return nullptr;
} else if (!current) {
if (p_wrap) {
current = this;
TreeItem *temp = get_next_visible();
while (temp) {
current = temp;
temp = temp->get_next_visible();
}
} else {
if (!current || (current == tree->root && tree->hide_root)) {
if (!p_wrap) {
return nullptr;
}
// Wrap around to the last visible item.
current = this;
TreeItem *temp = get_next_visible();
while (temp) {
current = temp;
temp = temp->get_next_visible();
}
}
} else {
current = prev_item;