From d499071e5b448a11fb3e815c33ab55cd4c23b5c1 Mon Sep 17 00:00:00 2001 From: Eric M Date: Sun, 23 Oct 2022 18:45:44 +1000 Subject: [PATCH] Set the shortcut context for the edit/search/goto menus to the ScriptEditor so that shortcuts continue to work when FindReplaceBar is focused. --- editor/plugins/script_editor_plugin.cpp | 8 ++++---- editor/plugins/script_editor_plugin.h | 2 +- editor/plugins/script_text_editor.cpp | 11 ++++++++++- editor/plugins/script_text_editor.h | 2 +- editor/plugins/text_editor.cpp | 11 ++++++++++- editor/plugins/text_editor.h | 2 +- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 876ef3bae95..b292ad8620a 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1734,7 +1734,7 @@ void ScriptEditor::ensure_select_current() { if (tab_container->get_tab_count() && tab_container->get_current_tab() >= 0) { ScriptEditorBase *se = _get_current_editor(); if (se) { - se->enable_editor(); + se->enable_editor(this); if (!grab_focus_block && is_visible_in_tree()) { se->ensure_focus(); @@ -2108,7 +2108,7 @@ void ScriptEditor::_update_script_names() { ScriptEditorBase *se = _get_current_editor(); if (se) { - se->enable_editor(); + se->enable_editor(this); _update_selected_editor_menu(); } } @@ -2273,7 +2273,7 @@ bool ScriptEditor::edit(const Ref &p_resource, int p_line, int p_col, if ((scr != nullptr && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) { if (should_open) { - se->enable_editor(); + se->enable_editor(this); if (tab_container->get_current_tab() != i) { _go_to_tab(i); @@ -2329,7 +2329,7 @@ bool ScriptEditor::edit(const Ref &p_resource, int p_line, int p_col, tab_container->add_child(se); if (p_grab_focus) { - se->enable_editor(); + se->enable_editor(this); } // If we delete a script within the filesystem, the original resource path diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index e69b8f8f827..a45ce4cc22c 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -139,7 +139,7 @@ public: virtual Ref get_edited_resource() const = 0; virtual Vector get_functions() = 0; virtual void set_edited_resource(const Ref &p_res) = 0; - virtual void enable_editor() = 0; + virtual void enable_editor(Control *p_shortcut_context = nullptr) = 0; virtual void reload_text() = 0; virtual String get_name() = 0; virtual Ref get_theme_icon() = 0; diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 7d7ef9245fb..e54a338c096 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -151,7 +151,7 @@ void ScriptTextEditor::set_edited_resource(const Ref &p_res) { code_editor->update_line_and_column(); } -void ScriptTextEditor::enable_editor() { +void ScriptTextEditor::enable_editor(Control *p_shortcut_context) { if (editor_enabled) { return; } @@ -161,6 +161,15 @@ void ScriptTextEditor::enable_editor() { _enable_code_editor(); _validate_script(); + + if (p_shortcut_context) { + for (int i = 0; i < edit_hb->get_child_count(); ++i) { + Control *c = cast_to(edit_hb->get_child(i)); + if (c) { + c->set_shortcut_context(p_shortcut_context); + } + } + } } void ScriptTextEditor::_load_theme_settings() { diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index c165295a8e1..5fd12674b38 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -206,7 +206,7 @@ public: virtual void apply_code() override; virtual Ref get_edited_resource() const override; virtual void set_edited_resource(const Ref &p_res) override; - virtual void enable_editor() override; + virtual void enable_editor(Control *p_shortcut_context = nullptr) override; virtual Vector get_functions() override; virtual void reload_text() override; virtual String get_name() override; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 07f0819c7fe..0c12b034472 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -108,7 +108,7 @@ void TextEditor::set_edited_resource(const Ref &p_res) { code_editor->update_line_and_column(); } -void TextEditor::enable_editor() { +void TextEditor::enable_editor(Control *p_shortcut_context) { if (editor_enabled) { return; } @@ -116,6 +116,15 @@ void TextEditor::enable_editor() { editor_enabled = true; _load_theme_settings(); + + if (p_shortcut_context) { + for (int i = 0; i < edit_hb->get_child_count(); ++i) { + Control *c = cast_to(edit_hb->get_child(i)); + if (c) { + c->set_shortcut_context(p_shortcut_context); + } + } + } } void TextEditor::add_callback(const String &p_function, PackedStringArray p_args) { diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index a7a640247fd..486a0f2c230 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -111,7 +111,7 @@ public: virtual Ref get_theme_icon() override; virtual Ref get_edited_resource() const override; virtual void set_edited_resource(const Ref &p_res) override; - virtual void enable_editor() override; + virtual void enable_editor(Control *p_shortcut_context = nullptr) override; virtual void reload_text() override; virtual void apply_code() override; virtual bool is_unsaved() override;