diff --git a/editor/docks/groups_editor.cpp b/editor/docks/groups_editor.cpp index 72a3c7546b0..09b6ed8eca0 100644 --- a/editor/docks/groups_editor.cpp +++ b/editor/docks/groups_editor.cpp @@ -515,7 +515,7 @@ void GroupsEditor::_confirm_add() { undo_redo->add_undo_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); undo_redo->commit_action(); - tree->grab_focus(); + tree->grab_focus(true); } void GroupsEditor::_confirm_rename() { @@ -566,7 +566,7 @@ void GroupsEditor::_confirm_rename() { undo_redo->commit_action(); - tree->grab_focus(); + tree->grab_focus(true); } void GroupsEditor::_confirm_delete() { @@ -606,7 +606,7 @@ void GroupsEditor::_confirm_delete() { undo_redo->add_undo_method(this, "_update_tree"); undo_redo->commit_action(); - tree->grab_focus(); + tree->grab_focus(true); } void GroupsEditor::_show_add_group_dialog() { diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index 62594f1928a..dddc9f90c19 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -277,6 +277,7 @@ void EditorSpinSlider::_value_input_gui_input(const Ref &p_event) { case Key::ESCAPE: { value_input_closed_frame = Engine::get_singleton()->get_frames_drawn(); if (value_input_popup) { + value_input_focus_visible = value_input->has_focus(true); value_input_popup->hide(); } } break; @@ -612,6 +613,7 @@ void EditorSpinSlider::_evaluate_input_text() { void EditorSpinSlider::_value_input_submitted(const String &p_text) { value_input_closed_frame = Engine::get_singleton()->get_frames_drawn(); if (value_input_popup) { + value_input_focus_visible = value_input->has_focus(true); value_input_popup->hide(); } } @@ -646,9 +648,10 @@ void EditorSpinSlider::_value_focus_exited() { value_input_popup->hide(); } } else { - // Enter or Esc was pressed. - grab_focus(); + // Enter or Esc was pressed. Keep showing the focus if already present. + grab_focus(!value_input_focus_visible); } + value_input_focus_visible = false; emit_signal("value_focus_exited"); } diff --git a/editor/gui/editor_spin_slider.h b/editor/gui/editor_spin_slider.h index e95f651f2d8..a72b5001950 100644 --- a/editor/gui/editor_spin_slider.h +++ b/editor/gui/editor_spin_slider.h @@ -67,6 +67,7 @@ class EditorSpinSlider : public Range { LineEdit *value_input = nullptr; uint64_t value_input_closed_frame = 0; bool value_input_dirty = false; + bool value_input_focus_visible = false; public: enum ControlState { diff --git a/editor/settings/action_map_editor.cpp b/editor/settings/action_map_editor.cpp index e3d4d7b69e6..1845d018186 100644 --- a/editor/settings/action_map_editor.cpp +++ b/editor/settings/action_map_editor.cpp @@ -435,6 +435,13 @@ void ActionMapEditor::update_action_list(const Vector &p_action_info actions_cache = p_action_infos; } + Pair selected_item; + TreeItem *ti = action_tree->get_selected(); + if (ti) { + selected_item.first = ti->get_text(0); + selected_item.second = action_tree->get_selected_column(); + } + HashSet collapsed_actions; TreeItem *root = action_tree->get_root(); if (root) { @@ -496,6 +503,10 @@ void ActionMapEditor::update_action_list(const Vector &p_action_info action_item->set_custom_bg_color(0, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor))); action_item->set_custom_bg_color(1, get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor))); + if (selected_item.first == action_info.name) { + action_item->select(selected_item.second); + } + for (int evnt_idx = 0; evnt_idx < events.size(); evnt_idx++) { Ref event = events[evnt_idx]; if (event.is_null()) { @@ -544,6 +555,10 @@ void ActionMapEditor::update_action_list(const Vector &p_action_info event_item->add_button(2, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_EVENT, false, TTRC("Remove Event"), TTRC("Remove Event")); event_item->set_button_color(2, 0, Color(1, 1, 1, 0.75)); event_item->set_button_color(2, 1, Color(1, 1, 1, 0.75)); + + if (selected_item.first == event_item->get_text(0)) { + event_item->select(selected_item.second); + } } } } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 557642486a2..2173a63cd95 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3285,9 +3285,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int click_handled = true; popup_pressing_edited_item = p_item; popup_pressing_edited_item_column = col; - - pressing_item_rect = Rect2(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - theme_cache.offset, Size2(col_width, item_h)); - pressing_for_editor_text = editor_text; pressing_for_editor = true; return -1; // Select. @@ -3361,14 +3358,15 @@ void Tree::_text_editor_gui_input(const Ref &p_event) { if (p_event->is_action_pressed("ui_text_newline_blank", true)) { accept_event(); } else if (p_event->is_action_pressed("ui_text_newline")) { + bool hide_focus = !text_editor->has_focus(true); popup_edit_committed = true; // End edit popup processing. popup_editor->hide(); - _apply_multiline_edit(); + _apply_multiline_edit(hide_focus); accept_event(); } } -void Tree::_apply_multiline_edit() { +void Tree::_apply_multiline_edit(bool p_hide_focus) { if (!popup_edited_item) { return; } @@ -3387,6 +3385,7 @@ void Tree::_apply_multiline_edit() { } } + grab_focus(p_hide_focus); item_edited(popup_edited_item_col, popup_edited_item); queue_redraw(); } @@ -3400,6 +3399,8 @@ void Tree::_line_editor_submit(String p_text) { return; // ESC pressed, app focus lost, or forced close from code. } + bool hide_focus = !line_editor->has_focus(true); + popup_edit_committed = true; // End edit popup processing. popup_editor->hide(); @@ -3432,6 +3433,7 @@ void Tree::_line_editor_submit(String p_text) { } } + grab_focus(hide_focus); item_edited(popup_edited_item_col, popup_edited_item); queue_redraw(); } @@ -4404,6 +4406,8 @@ bool Tree::edit_selected(bool p_force_edit) { } popup_rect.position += get_screen_position(); + bool hide_focus = !has_focus(true); + line_editor->clear(); line_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step))); line_editor->select_all(); @@ -4420,10 +4424,12 @@ bool Tree::edit_selected(bool p_force_edit) { popup_editor->popup(); popup_editor->child_controls_changed(); - line_editor->grab_focus(); + line_editor->grab_focus(hide_focus); return true; } else if (c.mode == TreeItem::CELL_MODE_STRING && c.edit_multiline) { + bool hide_focus = !has_focus(true); + line_editor->hide(); text_editor->clear(); @@ -4440,7 +4446,7 @@ bool Tree::edit_selected(bool p_force_edit) { popup_editor->popup(); popup_editor->child_controls_changed(); - text_editor->grab_focus(); + text_editor->grab_focus(hide_focus); return true; } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index fff16f4bb82..4df37298c01 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -480,9 +480,7 @@ private: int pressed_button = -1; bool pressing_for_editor = false; - String pressing_for_editor_text; Vector2 pressing_pos; - Rect2 pressing_item_rect; Vector2 hovered_pos; bool is_mouse_hovering = false; @@ -562,7 +560,7 @@ private: 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); 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 &p_mod); void _line_editor_submit(String p_text); - void _apply_multiline_edit(); + void _apply_multiline_edit(bool p_hide_focus = false); void _text_editor_popup_modal_close(); void _text_editor_gui_input(const Ref &p_event); void value_editor_changed(double p_value); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0415d43c161..e0e60a7ac75 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -552,7 +552,7 @@ bool Viewport::_can_hide_focus_state() { } void Viewport::_on_settings_changed() { - if (!gui.hide_focus && _can_hide_focus_state()) { + if (!gui.hide_focus || _can_hide_focus_state()) { return; }