From 45930e95e920012426764d8315b9651a77ce5371 Mon Sep 17 00:00:00 2001 From: Dawid Marzec Date: Sat, 14 Jan 2023 17:05:07 +0100 Subject: [PATCH] Fix Tree::deselect_all not deselecting root --- scene/gui/tree.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 339d8cce19f..45a8c48143a 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -4219,14 +4219,20 @@ Tree::SelectMode Tree::get_select_mode() const { } void Tree::deselect_all() { - TreeItem *item = get_next_selected(get_root()); - while (item) { - for (int i = 0; i < columns.size(); i++) { - item->deselect(i); + if (root) { + TreeItem *item = root; + while (item) { + if (select_mode == SELECT_ROW) { + item->deselect(0); + } else { + for (int i = 0; i < columns.size(); i++) { + item->deselect(i); + } + } + TreeItem *prev_item = item; + item = get_next_selected(root); + ERR_FAIL_COND(item == prev_item); } - TreeItem *prev_item = item; - item = get_next_selected(get_root()); - ERR_FAIL_COND(item == prev_item); } selected_item = nullptr;