From 9996bf369a4ff37225e5be9c3538c1e7e7d6ee64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Sun, 30 Mar 2025 11:48:39 +0800 Subject: [PATCH] Fix setting root inspector's `follow_focus` to `true` when `update_tree()` method ends This may produce unexpected behavior in **recursive** calls. --- editor/editor_inspector.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 20b2e830f5..1d6c5858cb 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3281,14 +3281,21 @@ bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName } void EditorInspector::update_tree() { + if (!object) { + return; + } + + bool root_inspector_was_following_focus = get_root_inspector()->is_following_focus(); + if (root_inspector_was_following_focus) { + // Temporarily disable focus following on the root inspector to avoid jumping while the inspector is updating. + get_root_inspector()->set_follow_focus(false); + } + // Store currently selected and focused elements to restore after the update. // TODO: Can be useful to store more context for the focusable, such as the caret position in LineEdit. StringName current_selected = property_selected; int current_focusable = -1; - // Temporarily disable focus following on the root inspector to avoid jumping while the inspector is updating. - get_root_inspector()->set_follow_focus(false); - if (property_focusable != -1) { // Check that focusable is actually focusable. bool restore_focus = false; @@ -3310,14 +3317,9 @@ void EditorInspector::update_tree() { } } - // Only hide plugins if we are not editing any object. - // This should be handled outside of the update_tree call anyway (see EditorInspector::edit), but might as well keep it safe. - _clear(!object); - - if (!object) { - get_root_inspector()->set_follow_focus(true); - return; - } + // The call here is for the edited object that has not changed, but the tree needs to be updated (for example, the object's property list has been modified). + // Since the edited object has not changed, there is no need to hide the plugin at this time. + _clear(false); List> valid_plugins; @@ -4201,7 +4203,9 @@ void EditorInspector::update_tree() { EditorNode::get_singleton()->hide_unused_editors(); } - get_root_inspector()->set_follow_focus(true); + if (root_inspector_was_following_focus) { + get_root_inspector()->set_follow_focus(true); + } } void EditorInspector::update_property(const String &p_prop) {