Repository: godotengine/godot (language: cpp)

Issue:
Inspector scrolls away when editing properties with a nested property unfolded
### Tested versions

4.4.1stable mono

### System information

Windows 10 x64, Nvidia

### Issue description

The Inspector scrolls away when editing a property. 
Strangely this only occurs when a nested property is also inside the inspector( for example a 'sky' Background inside a worldenvironment Node)
See video:

https://github.com/user-attachments/assets/842d2436-4219-4096-80c0-f095894eba52



May be linked to https://github.com/godotengine/godot/pull/96542 ?

### Steps to reproduce

Create a world enviromnent node inside a scene.

2) Click a few properties inside worldenvironment to expand them ... e.g. Glow, Fog
3) Note no scrolling away when clicked
4) Now, go to 'Background' property & create a 'Sky' ->New Sky -> Panoramic Sky
5) Go back to 'Glow' or "Fog' and see how it scrolls away now

### Minimal reproduction project (MRP)

None


Discussion / hints:
Tested on 4.4 stable and works as expected so this is a recent regression, bisecting.
Bisected to commit ba27815166b1ef63eda94dde423499bd8edc39e2 from pr #104358 as the culprit. CC @Rindbee

![Image](https://github.com/user-attachments/assets/a1c015f1-44bf-4912-b717-5566704e66b1)
This is odd, and seems to only be reproducible when the `Sky` resource is expanded. I will investigate further.

Fix patch:
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 20b2e830f5d8..1d6c5858cb4c 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<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) {


Test patch: