From ed687b84a3d58e5676138f57860897430ba28738 Mon Sep 17 00:00:00 2001 From: kit Date: Mon, 3 Nov 2025 18:34:35 -0500 Subject: [PATCH] Use only one edit menu for TextEditors --- editor/script/script_editor_plugin.cpp | 39 +- editor/script/script_editor_plugin.h | 7 +- editor/script/script_text_editor.cpp | 490 +++++++++++++------------ editor/script/script_text_editor.h | 47 ++- editor/script/text_editor.cpp | 351 ++++++++++-------- editor/script/text_editor.h | 37 +- 6 files changed, 515 insertions(+), 456 deletions(-) diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp index bb28ac7ea82..5e115562de1 100644 --- a/editor/script/script_editor_plugin.cpp +++ b/editor/script/script_editor_plugin.cpp @@ -919,7 +919,6 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { int idx = tab_container->get_current_tab(); if (current) { - current->clear_edit_menu(); _save_editor_state(current); } memdelete(tselected); @@ -2080,7 +2079,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(this); + se->enable_editor(); if (!grab_focus_block && is_visible_in_tree()) { se->ensure_focus(); @@ -2499,7 +2498,7 @@ void ScriptEditor::_update_script_names() { ScriptEditorBase *se = _get_current_editor(); if (se) { - se->enable_editor(this); + se->enable_editor(); _update_selected_editor_menu(); } } @@ -2624,7 +2623,7 @@ bool ScriptEditor::edit(const Ref &p_resource, int p_line, int p_col, if ((scr.is_valid() && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) { if (should_open) { - se->enable_editor(this); + se->enable_editor(); if (tab_container->get_current_tab() != i) { _go_to_tab(i); @@ -2689,7 +2688,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(this); + se->enable_editor(); } // If we delete a script within the filesystem, the original resource path @@ -2699,10 +2698,18 @@ bool ScriptEditor::edit(const Ref &p_resource, int p_line, int p_col, se->set_tooltip_request_func(callable_mp(this, &ScriptEditor::_get_debug_tooltip)); - if (se->get_edit_menu()) { - se->get_edit_menu()->hide(); - menu_hb->add_child(se->get_edit_menu()); - menu_hb->move_child(se->get_edit_menu(), 1); + Control *editor_edit_menu = se->get_edit_menu(); + if (editor_edit_menu && !editor_edit_menu->get_parent()) { + editor_edit_menu->hide(); + editor_menus.push_back(editor_edit_menu); + menu_hb->add_child(editor_edit_menu); + menu_hb->move_child(editor_edit_menu, 1); + for (int i = 0; i < editor_edit_menu->get_child_count(); ++i) { + Control *c = Object::cast_to(editor_edit_menu->get_child(i)); + if (c) { + c->set_shortcut_context(this); + } + } } if (p_grab_focus) { @@ -3829,17 +3836,9 @@ void ScriptEditor::update_docs_from_script(const Ref