Skip to content

Commit

Permalink
Merge pull request #93179 from TheSofox/tree-nav-crash
Browse files Browse the repository at this point in the history
Fix engine crashing when using Down Arrow selection on Tree with no selection
  • Loading branch information
akien-mga committed Jun 24, 2024
2 parents 6882a94 + d86e025 commit bf20231
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3354,15 +3354,16 @@ void Tree::_go_up() {
prev = selected_item->get_prev_visible();
}

int col = MAX(selected_col, 0);

if (select_mode == SELECT_MULTI) {
if (!prev) {
return;
}

select_single_item(prev, get_root(), selected_col);
select_single_item(prev, get_root(), col);
queue_redraw();
} else {
int col = selected_col < 0 ? 0 : selected_col;
while (prev && !prev->cells[col].selectable) {
prev = prev->get_prev_visible();
}
Expand All @@ -3386,16 +3387,16 @@ void Tree::_go_down() {
next = selected_item->get_next_visible();
}

int col = MAX(selected_col, 0);

if (select_mode == SELECT_MULTI) {
if (!next) {
return;
}

select_single_item(next, get_root(), selected_col);
select_single_item(next, get_root(), col);
queue_redraw();
} else {
int col = selected_col < 0 ? 0 : selected_col;

while (next && !next->cells[col].selectable) {
next = next->get_next_visible();
}
Expand Down Expand Up @@ -4471,7 +4472,7 @@ TreeItem *Tree::get_last_item() const {
while (last) {
if (last->next) {
last = last->next;
} else if (last->first_child) {
} else if (last->first_child && !last->collapsed) {
last = last->first_child;
} else {
break;
Expand Down

0 comments on commit bf20231

Please sign in to comment.