From ccff2f2551c5749e1c7d2976222013f582d767b1 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Wed, 20 Nov 2019 10:09:59 +0100 Subject: 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 | 61 ++++--- editor/plugins/script_editor_plugin.h | 1 + editor/plugins/script_text_editor.cpp | 228 +++++++++++++++---------- editor/plugins/script_text_editor.h | 43 ++--- editor/plugins/text_editor.cpp | 42 +++-- editor/plugins/text_editor.h | 21 ++- modules/visual_script/visual_script_editor.cpp | 5 + modules/visual_script/visual_script_editor.h | 1 + 9 files changed, 242 insertions(+), 162 deletions(-) diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index d8648310b6..1884816386 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1456,8 +1456,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 4f783f4e27..f1bfd5617c 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -696,7 +696,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