Skip to content

Commit 40ff57e

Browse files
committed
Merge pull request #102775 from KoBeWi/😐
Fix inspector follow focus when child is focused
2 parents b2aae7b + 286d3ae commit 40ff57e

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

β€Žeditor/editor_inspector.cppβ€Ž

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,6 +4465,14 @@ void EditorInspector::_node_removed(Node *p_node) {
44654465
}
44664466
}
44674467

4468+
void EditorInspector::_gui_focus_changed(Control *p_control) {
4469+
if (!is_visible_in_tree() && !is_following_focus()) {
4470+
return;
4471+
}
4472+
// Don't follow focus when the inspector nor any of its children is focused. Prevents potential jumping when gaining focus.
4473+
set_follow_focus(has_focus() || child_has_focus());
4474+
}
4475+
44684476
void EditorInspector::_update_current_favorites() {
44694477
current_favorites.clear();
44704478
if (!can_favorite) {
@@ -4662,6 +4670,10 @@ void EditorInspector::_notification(int p_what) {
46624670
if (!is_sub_inspector()) {
46634671
get_tree()->connect("node_removed", callable_mp(this, &EditorInspector::_node_removed));
46644672
}
4673+
4674+
Viewport *viewport = get_viewport();
4675+
ERR_FAIL_NULL(viewport);
4676+
viewport->connect("gui_focus_changed", callable_mp(this, &EditorInspector::_gui_focus_changed));
46654677
} break;
46664678

46674679
case NOTIFICATION_PREDELETE: {
@@ -4744,15 +4756,6 @@ void EditorInspector::_notification(int p_what) {
47444756
update_tree();
47454757
}
47464758
} break;
4747-
4748-
case NOTIFICATION_FOCUS_ENTER: {
4749-
set_follow_focus(true);
4750-
} break;
4751-
4752-
case NOTIFICATION_FOCUS_EXIT: {
4753-
// Don't follow focus when the inspector is not focused. Prevents potential jumping when gaining focus.
4754-
set_follow_focus(false);
4755-
} break;
47564759
}
47574760
}
47584761

β€Žeditor/editor_inspector.hβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ class EditorInspector : public ScrollContainer {
606606
void _clear_current_favorites();
607607

608608
void _node_removed(Node *p_node);
609+
void _gui_focus_changed(Control *p_control);
609610

610611
HashMap<StringName, int> per_array_page;
611612
void _page_change_request(int p_new_page, const StringName &p_array_prefix);

β€Žscene/gui/scroll_container.hβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class ScrollContainer : public Container {
8282

8383
bool draw_focus_border = false;
8484
bool focus_border_is_drawn = false;
85-
bool child_has_focus();
8685

8786
protected:
8887
Size2 get_minimum_size() const override;
@@ -99,6 +98,7 @@ class ScrollContainer : public Container {
9998

10099
public:
101100
virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
101+
bool child_has_focus();
102102

103103
void set_h_scroll(int p_pos);
104104
int get_h_scroll() const;

0 commit comments

Comments
Β (0)