From 09f967bc00b5d8ed6e71e071aa891d39e56092e8 Mon Sep 17 00:00:00 2001 From: passivestar <60579014+passivestar@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:44:06 +0400 Subject: [PATCH] Prevent node rename shortcut from stealing focus from controls --- editor/gui/editor_spin_slider.cpp | 4 ++++ editor/gui/editor_spin_slider.h | 2 ++ editor/scene_tree_dock.cpp | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/editor/gui/editor_spin_slider.cpp b/editor/gui/editor_spin_slider.cpp index a838299288b..1d798f285b4 100644 --- a/editor/gui/editor_spin_slider.cpp +++ b/editor/gui/editor_spin_slider.cpp @@ -36,6 +36,10 @@ #include "editor/editor_settings.h" #include "editor/themes/editor_scale.h" +bool EditorSpinSlider::is_text_field() const { + return true; +} + String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { if (!read_only && grabber->is_visible()) { Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL; diff --git a/editor/gui/editor_spin_slider.h b/editor/gui/editor_spin_slider.h index a999f5c48f1..a0c06856292 100644 --- a/editor/gui/editor_spin_slider.h +++ b/editor/gui/editor_spin_slider.h @@ -96,6 +96,8 @@ protected: void _focus_entered(); public: + virtual bool is_text_field() const override; + String get_tooltip(const Point2 &p_pos) const override; String get_text_value() const; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 11e477e0443..aa41ec6135c 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -148,7 +148,8 @@ void SceneTreeDock::input(const Ref &p_event) { void SceneTreeDock::shortcut_input(const Ref &p_event) { ERR_FAIL_COND(p_event.is_null()); - if (get_viewport()->gui_get_focus_owner() && get_viewport()->gui_get_focus_owner()->is_text_field()) { + Control *focus_owner = get_viewport()->gui_get_focus_owner(); + if (focus_owner && focus_owner->is_text_field()) { return; } @@ -157,7 +158,11 @@ void SceneTreeDock::shortcut_input(const Ref &p_event) { } if (ED_IS_SHORTCUT("scene_tree/rename", p_event)) { - _tool_selected(TOOL_RENAME); + // Prevent renaming if a button is focused + // to avoid conflict with Enter shortcut on macOS + if (!focus_owner || !Object::cast_to(focus_owner)) { + _tool_selected(TOOL_RENAME); + } #ifdef MODULE_REGEX_ENABLED } else if (ED_IS_SHORTCUT("scene_tree/batch_rename", p_event)) { _tool_selected(TOOL_BATCH_RENAME);