From e3765e97de6c85f5893472ba504f65a49ccc091f Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Wed, 15 Jul 2020 16:15:29 +0200 Subject: [PATCH] Optimized ScriptEditor initialization when many scripts are loaded This change avoids the editor to freeze for several seconds when a project with lots of scripts is loaded in the editor. It focuses on a few heavy operations previously executed on all previously loaded scripts: - Initialize script resource (script validation/parsing) only on focus - ScriptTextEditor: code editor and edit menu are added to the scene only on focus - Add to recent scripts only when opening new scripts (load/save scene metadata) --- editor/code_editor.cpp | 2 - editor/plugins/script_editor_plugin.cpp | 63 +++-- editor/plugins/script_editor_plugin.h | 1 + editor/plugins/script_text_editor.cpp | 236 +++++++++++------- editor/plugins/script_text_editor.h | 7 +- editor/plugins/text_editor.cpp | 29 ++- editor/plugins/text_editor.h | 5 +- .../visual_script/visual_script_editor.cpp | 6 +- modules/visual_script/visual_script_editor.h | 1 + 9 files changed, 226 insertions(+), 124 deletions(-) diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 8d9c817d9dd..f6daaecf7e0 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1462,8 +1462,6 @@ void CodeTextEditor::set_edit_state(const Variant &p_state) { text_editor->set_line_as_bookmark(bookmarks[i], true); } } - - text_editor->grab_focus(); } void CodeTextEditor::set_error(const String &p_error) { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 99c3d87168f..d8620f2dab2 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -580,7 +580,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { Node *tselected = tab_container->get_child(selected); - ScriptEditorBase *current = Object::cast_to(tab_container->get_child(selected)); + ScriptEditorBase *current = Object::cast_to(tselected); if (current) { Ref