Repository: godotengine/godot (language: cpp)

Issue:
Inspector can't navigate with arrow keys or tab key if control outside scroll view
### Tested versions

v4.4.beta3.official [06acfccf8]

not in v4.4.beta1.official [d33da79d3]

### System information

Fedora 40

### Issue description

Inspector can't navigate with arrow keys or tab key if control outside scroll view. 
Sounds like this PR https://github.com/godotengine/godot/pull/63059 can be one cause for this.

4.4.beta3
First tab then arrow keys

https://github.com/user-attachments/assets/651afc7b-a658-432b-8105-911e5c7ad1ee

4.4.beta1

https://github.com/user-attachments/assets/6560fb43-fea9-47e9-8016-642c1d78ca8e




### Steps to reproduce

In the inspector unfold so its get big enough to be able to scroll.
Try to navigate with arrow keys or tab key

### Minimal reproduction project (MRP)

N/A


Discussion / hints:
Same behavior in Editor Settings:

https://github.com/user-attachments/assets/173afea5-66f6-4443-ba1b-2d770a2055fe
I tested it with the builds from artifacts in #63059 and #101625 and couldn't reproduce it. It can still be reproduced after `git revert e1974635250ea5a34ba92e66a93974d0d6549b59`.
Bisected to 922642440132bf7b070a16240c3a21d119584403, #101768.
CC @KoBeWi 

This change was to solve:
* https://github.com/godotengine/godot/issues/100695

Fix patch:
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 97335821374e..be8f917ec49a 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -4465,6 +4465,14 @@ void EditorInspector::_node_removed(Node *p_node) {
 	}
 }
 
+void EditorInspector::_gui_focus_changed(Control *p_control) {
+	if (!is_visible_in_tree() && !is_following_focus()) {
+		return;
+	}
+	// Don't follow focus when the inspector nor any of its children is focused. Prevents potential jumping when gaining focus.
+	set_follow_focus(has_focus() || child_has_focus());
+}
+
 void EditorInspector::_update_current_favorites() {
 	current_favorites.clear();
 	if (!can_favorite) {
@@ -4662,6 +4670,10 @@ void EditorInspector::_notification(int p_what) {
 			if (!is_sub_inspector()) {
 				get_tree()->connect("node_removed", callable_mp(this, &EditorInspector::_node_removed));
 			}
+
+			Viewport *viewport = get_viewport();
+			ERR_FAIL_NULL(viewport);
+			viewport->connect("gui_focus_changed", callable_mp(this, &EditorInspector::_gui_focus_changed));
 		} break;
 
 		case NOTIFICATION_PREDELETE: {
@@ -4744,15 +4756,6 @@ void EditorInspector::_notification(int p_what) {
 				update_tree();
 			}
 		} break;
-
-		case NOTIFICATION_FOCUS_ENTER: {
-			set_follow_focus(true);
-		} break;
-
-		case NOTIFICATION_FOCUS_EXIT: {
-			// Don't follow focus when the inspector is not focused. Prevents potential jumping when gaining focus.
-			set_follow_focus(false);
-		} break;
 	}
 }
 
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index ee82806003b2..9baf65444f27 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -606,6 +606,7 @@ class EditorInspector : public ScrollContainer {
 	void _clear_current_favorites();
 
 	void _node_removed(Node *p_node);
+	void _gui_focus_changed(Control *p_control);
 
 	HashMap<StringName, int> per_array_page;
 	void _page_change_request(int p_new_page, const StringName &p_array_prefix);
diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h
index ea6309f57e80..408f70157dfe 100644
--- a/scene/gui/scroll_container.h
+++ b/scene/gui/scroll_container.h
@@ -82,7 +82,6 @@ class ScrollContainer : public Container {
 
 	bool draw_focus_border = false;
 	bool focus_border_is_drawn = false;
-	bool child_has_focus();
 
 protected:
 	Size2 get_minimum_size() const override;
@@ -99,6 +98,7 @@ class ScrollContainer : public Container {
 
 public:
 	virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
+	bool child_has_focus();
 
 	void set_h_scroll(int p_pos);
 	int get_h_scroll() const;


Test patch: