Skip to content

Commit e32b927

Browse files
committed
Fix UI focus being shown when it shouldn't
1 parent 06faefc commit e32b927

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

editor/docks/groups_editor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ void GroupsEditor::_confirm_add() {
515515
undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree");
516516

517517
undo_redo->commit_action();
518-
tree->grab_focus();
518+
tree->grab_focus(true);
519519
}
520520

521521
void GroupsEditor::_confirm_rename() {
@@ -566,7 +566,7 @@ void GroupsEditor::_confirm_rename() {
566566

567567
undo_redo->commit_action();
568568

569-
tree->grab_focus();
569+
tree->grab_focus(true);
570570
}
571571

572572
void GroupsEditor::_confirm_delete() {
@@ -606,7 +606,7 @@ void GroupsEditor::_confirm_delete() {
606606
undo_redo->add_undo_method(this, "_update_tree");
607607

608608
undo_redo->commit_action();
609-
tree->grab_focus();
609+
tree->grab_focus(true);
610610
}
611611

612612
void GroupsEditor::_show_add_group_dialog() {

editor/gui/editor_spin_slider.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
277277
case Key::ESCAPE: {
278278
value_input_closed_frame = Engine::get_singleton()->get_frames_drawn();
279279
if (value_input_popup) {
280+
value_input_focus_visible = value_input->has_focus(true);
280281
value_input_popup->hide();
281282
}
282283
} break;
@@ -612,6 +613,7 @@ void EditorSpinSlider::_evaluate_input_text() {
612613
void EditorSpinSlider::_value_input_submitted(const String &p_text) {
613614
value_input_closed_frame = Engine::get_singleton()->get_frames_drawn();
614615
if (value_input_popup) {
616+
value_input_focus_visible = value_input->has_focus(true);
615617
value_input_popup->hide();
616618
}
617619
}
@@ -646,9 +648,10 @@ void EditorSpinSlider::_value_focus_exited() {
646648
value_input_popup->hide();
647649
}
648650
} else {
649-
// Enter or Esc was pressed.
650-
grab_focus();
651+
// Enter or Esc was pressed. Keep showing the focus if already present.
652+
grab_focus(!value_input_focus_visible);
651653
}
654+
value_input_focus_visible = false;
652655

653656
emit_signal("value_focus_exited");
654657
}

editor/gui/editor_spin_slider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class EditorSpinSlider : public Range {
6767
LineEdit *value_input = nullptr;
6868
uint64_t value_input_closed_frame = 0;
6969
bool value_input_dirty = false;
70+
bool value_input_focus_visible = false;
7071

7172
public:
7273
enum ControlState {

editor/settings/action_map_editor.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
435435
actions_cache = p_action_infos;
436436
}
437437

438+
Pair<String, int> selected_item;
439+
TreeItem *ti = action_tree->get_selected();
440+
if (ti) {
441+
selected_item.first = ti->get_text(0);
442+
selected_item.second = action_tree->get_selected_column();
443+
}
444+
438445
HashSet<String> collapsed_actions;
439446
TreeItem *root = action_tree->get_root();
440447
if (root) {
@@ -496,6 +503,10 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
496503
action_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
497504
action_item->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
498505

506+
if (selected_item.first == action_info.name) {
507+
action_item->select(selected_item.second);
508+
}
509+
499510
for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) {
500511
Ref<InputEvent> event = events[evnt_idx];
501512
if (event.is_null()) {
@@ -544,6 +555,10 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
544555
event_item->add_button(2, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTRC("Remove Event"), TTRC("Remove Event"));
545556
event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
546557
event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75));
558+
559+
if (selected_item.first == event_item->get_text(0)) {
560+
event_item->select(selected_item.second);
561+
}
547562
}
548563
}
549564
}

scene/gui/tree.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,9 +3285,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
32853285
click_handled = true;
32863286
popup_pressing_edited_item = p_item;
32873287
popup_pressing_edited_item_column = col;
3288-
3289-
pressing_item_rect = Rect2(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - theme_cache.offset, Size2(col_width, item_h));
3290-
pressing_for_editor_text = editor_text;
32913288
pressing_for_editor = true;
32923289

32933290
return -1; // Select.
@@ -3361,14 +3358,15 @@ void Tree::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
33613358
if (p_event->is_action_pressed("ui_text_newline_blank", true)) {
33623359
accept_event();
33633360
} else if (p_event->is_action_pressed("ui_text_newline")) {
3361+
bool hide_focus = !text_editor->has_focus(true);
33643362
popup_edit_committed = true; // End edit popup processing.
33653363
popup_editor->hide();
3366-
_apply_multiline_edit();
3364+
_apply_multiline_edit(hide_focus);
33673365
accept_event();
33683366
}
33693367
}
33703368

3371-
void Tree::_apply_multiline_edit() {
3369+
void Tree::_apply_multiline_edit(bool p_hide_focus) {
33723370
if (!popup_edited_item) {
33733371
return;
33743372
}
@@ -3387,6 +3385,7 @@ void Tree::_apply_multiline_edit() {
33873385
}
33883386
}
33893387

3388+
grab_focus(p_hide_focus);
33903389
item_edited(popup_edited_item_col, popup_edited_item);
33913390
queue_redraw();
33923391
}
@@ -3400,6 +3399,8 @@ void Tree::_line_editor_submit(String p_text) {
34003399
return; // ESC pressed, app focus lost, or forced close from code.
34013400
}
34023401

3402+
bool hide_focus = !line_editor->has_focus(true);
3403+
34033404
popup_edit_committed = true; // End edit popup processing.
34043405
popup_editor->hide();
34053406

@@ -3432,6 +3433,7 @@ void Tree::_line_editor_submit(String p_text) {
34323433
}
34333434
}
34343435

3436+
grab_focus(hide_focus);
34353437
item_edited(popup_edited_item_col, popup_edited_item);
34363438
queue_redraw();
34373439
}
@@ -4404,6 +4406,8 @@ bool Tree::edit_selected(bool p_force_edit) {
44044406
}
44054407
popup_rect.position += get_screen_position();
44064408

4409+
bool hide_focus = !has_focus(true);
4410+
44074411
line_editor->clear();
44084412
line_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step)));
44094413
line_editor->select_all();
@@ -4420,10 +4424,12 @@ bool Tree::edit_selected(bool p_force_edit) {
44204424
popup_editor->popup();
44214425
popup_editor->child_controls_changed();
44224426

4423-
line_editor->grab_focus();
4427+
line_editor->grab_focus(hide_focus);
44244428

44254429
return true;
44264430
} else if (c.mode == TreeItem::CELL_MODE_STRING && c.edit_multiline) {
4431+
bool hide_focus = !has_focus(true);
4432+
44274433
line_editor->hide();
44284434

44294435
text_editor->clear();
@@ -4440,7 +4446,7 @@ bool Tree::edit_selected(bool p_force_edit) {
44404446
popup_editor->popup();
44414447
popup_editor->child_controls_changed();
44424448

4443-
text_editor->grab_focus();
4449+
text_editor->grab_focus(hide_focus);
44444450

44454451
return true;
44464452
}

scene/gui/tree.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,7 @@ class Tree : public Control {
480480

481481
int pressed_button = -1;
482482
bool pressing_for_editor = false;
483-
String pressing_for_editor_text;
484483
Vector2 pressing_pos;
485-
Rect2 pressing_item_rect;
486484

487485
Vector2 hovered_pos;
488486
bool is_mouse_hovering = false;
@@ -562,7 +560,7 @@ class Tree : public Control {
562560
void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false);
563561
int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int x_limit, bool p_double_click, TreeItem *p_item, MouseButton p_button, const Ref<InputEventWithModifiers> &p_mod);
564562
void _line_editor_submit(String p_text);
565-
void _apply_multiline_edit();
563+
void _apply_multiline_edit(bool p_hide_focus = false);
566564
void _text_editor_popup_modal_close();
567565
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
568566
void value_editor_changed(double p_value);

scene/main/viewport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ bool Viewport::_can_hide_focus_state() {
552552
}
553553

554554
void Viewport::_on_settings_changed() {
555-
if (!gui.hide_focus && _can_hide_focus_state()) {
555+
if (!gui.hide_focus || _can_hide_focus_state()) {
556556
return;
557557
}
558558

0 commit comments

Comments
 (0)