Skip to content

Commit

Permalink
Prevent node rename shortcut from stealing focus from controls
Browse files Browse the repository at this point in the history
  • Loading branch information
passivestar committed Jul 9, 2024
1 parent 71699e0 commit 09f967b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions editor/gui/editor_spin_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions editor/gui/editor_spin_slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class EditorSpinSlider : public Range {
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;
Expand Down
9 changes: 7 additions & 2 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ void SceneTreeDock::input(const Ref<InputEvent> &p_event) {
void SceneTreeDock::shortcut_input(const Ref<InputEvent> &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;
}

Expand All @@ -157,7 +158,11 @@ void SceneTreeDock::shortcut_input(const Ref<InputEvent> &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<BaseButton>(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);
Expand Down

0 comments on commit 09f967b

Please sign in to comment.