Skip to content

Commit 25203e2

Browse files
committed
Merge pull request #112895 from YeldhamDev/project_list_focus_fix
Hide mouse focus from project list
2 parents dec0b22 + d949144 commit 25203e2

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

editor/project_manager/project_list.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ void ProjectListItemControl::_notification(int p_what) {
142142
if (is_hovering) {
143143
draw_style_box(get_theme_stylebox(SNAME("hovered"), SNAME("Tree")), Rect2(Point2(), get_size()));
144144
}
145-
if (has_focus()) {
145+
// Due to how this control works, we can't rely on the built-in way of checking for focus visibility.
146+
if (has_focus() && !is_focus_hidden) {
146147
draw_style_box(get_theme_stylebox(SNAME("focus"), SNAME("Tree")), Rect2(Point2(), get_size()));
147148
}
148149

@@ -296,8 +297,9 @@ bool ProjectListItemControl::should_load_project_icon() const {
296297
return icon_needs_reload;
297298
}
298299

299-
void ProjectListItemControl::set_selected(bool p_selected) {
300+
void ProjectListItemControl::set_selected(bool p_selected, bool p_hide_focus) {
300301
is_selected = p_selected;
302+
is_focus_hidden = is_selected && p_hide_focus;
301303
queue_redraw();
302304
queue_accessibility_update();
303305
}
@@ -1017,7 +1019,7 @@ int ProjectList::get_index(const ProjectListItemControl *p_control) const {
10171019
void ProjectList::ensure_project_visible(int p_index) {
10181020
const Item &item = _projects[p_index];
10191021
// Since follow focus is enabled.
1020-
item.control->grab_focus();
1022+
item.control->grab_focus(true);
10211023
}
10221024

10231025
void ProjectList::_create_project_item_control(int p_index) {
@@ -1111,7 +1113,7 @@ void ProjectList::_list_item_input(const Ref<InputEvent> &p_ev, Control *p_hb) {
11111113

11121114
} else {
11131115
_last_clicked = clicked_project.path;
1114-
select_project(clicked_index);
1116+
select_project(clicked_index, true);
11151117
}
11161118

11171119
emit_signal(SNAME(SIGNAL_SELECTION_CHANGED));
@@ -1255,10 +1257,10 @@ void ProjectList::_clear_project_selection() {
12551257
queue_accessibility_update();
12561258
}
12571259

1258-
void ProjectList::_select_project_nocheck(int p_index) {
1260+
void ProjectList::_select_project_nocheck(int p_index, bool p_hide_focus) {
12591261
Item &item = _projects.write[p_index];
12601262
_selected_project_paths.insert(item.path);
1261-
item.control->set_selected(true);
1263+
item.control->set_selected(true, p_hide_focus);
12621264
queue_accessibility_update();
12631265
}
12641266

@@ -1286,10 +1288,10 @@ void ProjectList::_select_project_range(int p_begin, int p_end) {
12861288
}
12871289
}
12881290

1289-
void ProjectList::select_project(int p_index) {
1291+
void ProjectList::select_project(int p_index, bool p_hide_focus) {
12901292
// This method keeps only one project selected.
12911293
_clear_project_selection();
1292-
_select_project_nocheck(p_index);
1294+
_select_project_nocheck(p_index, p_hide_focus);
12931295
}
12941296

12951297
void ProjectList::deselect_project(int p_index) {

editor/project_manager/project_list.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ProjectListItemControl : public HBoxContainer {
6464
bool project_is_missing = false;
6565
bool icon_needs_reload = true;
6666
bool is_selected = false;
67+
bool is_focus_hidden = false;
6768
bool is_hovering = false;
6869
bool is_favorite = false;
6970

@@ -93,7 +94,7 @@ class ProjectListItemControl : public HBoxContainer {
9394
void set_unsupported_features(PackedStringArray p_features);
9495

9596
bool should_load_project_icon() const;
96-
void set_selected(bool p_selected);
97+
void set_selected(bool p_selected, bool p_hide_focus = false);
9798

9899
void set_is_favorite(bool p_favorite);
99100
void set_is_missing(bool p_missing);
@@ -261,7 +262,7 @@ class ProjectList : public ScrollContainer {
261262
// Project list selection.
262263

263264
void _clear_project_selection();
264-
void _select_project_nocheck(int p_index);
265+
void _select_project_nocheck(int p_index, bool p_hide_focus = false);
265266
void _deselect_project_nocheck(int p_index);
266267
void _select_project_range(int p_begin, int p_end);
267268

@@ -306,7 +307,7 @@ class ProjectList : public ScrollContainer {
306307

307308
// Project list selection.
308309

309-
void select_project(int p_index);
310+
void select_project(int p_index, bool p_hide_focus = false);
310311
void deselect_project(int p_index);
311312
void select_first_visible_project();
312313
void select_all_visible_projects();

0 commit comments

Comments
 (0)