From e46280dbb56dd7d8bdb2b25bbefe363b2a8e455b Mon Sep 17 00:00:00 2001 From: Hilderin <81109165+Hilderin@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:35:16 -0400 Subject: [PATCH] Fix scene node selection problem when no auto expand --- editor/gui/scene_tree_editor.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index a3e62c298f7..91c70138f26 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -1000,6 +1000,7 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) { TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr; if (item) { + selected = p_node; if (auto_expand_selected) { // Make visible when it's collapsed. TreeItem *node = item->get_parent(); @@ -1009,8 +1010,24 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) { } item->select(0); item->set_as_cursor(0); - selected = p_node; tree->ensure_cursor_is_visible(); + } else { + // Ensure the node is selected and visible for the user if the node + // is not collapsed. + bool collapsed = false; + TreeItem *node = item; + while (node && node != tree->get_root()) { + if (node->is_collapsed()) { + collapsed = true; + break; + } + node = node->get_parent(); + } + if (!collapsed) { + item->select(0); + item->set_as_cursor(0); + tree->ensure_cursor_is_visible(); + } } } else { if (!p_node) {