Ver Fonte

Merge pull request #104785 from Rindbee/fix-root-inspector-follow_focus-set-to-true

Fix setting root inspector's `follow_focus` to `true` when `update_tree()` method ends
Thaddeus Crews há 5 meses atrás
pai
commit
70b1647ef4
1 ficheiros alterados com 16 adições e 12 exclusões
  1. 16 12
      editor/editor_inspector.cpp

+ 16 - 12
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<Ref<EditorInspectorPlugin>> 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) {