From 835383d46b76be25000869047de26e3d35995880 Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 26 Sep 2025 23:19:51 +0200 Subject: [PATCH] Fix region folding not loading properly --- editor/script/script_text_editor.cpp | 15 ++++++++++++++- editor/script/script_text_editor.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/editor/script/script_text_editor.cpp b/editor/script/script_text_editor.cpp index c61fa0f1069..c37b4035252 100644 --- a/editor/script/script_text_editor.cpp +++ b/editor/script/script_text_editor.cpp @@ -184,6 +184,11 @@ void ScriptTextEditor::enable_editor(Control *p_shortcut_context) { _validate_script(); + if (pending_state != Variant()) { + code_editor->set_edit_state(pending_state); + pending_state = Variant(); + } + if (p_shortcut_context) { for (int i = 0; i < edit_hb->get_child_count(); ++i) { Control *c = cast_to(edit_hb->get_child(i)); @@ -704,11 +709,19 @@ bool ScriptTextEditor::is_unsaved() { } Variant ScriptTextEditor::get_edit_state() { + if (pending_state != Variant()) { + return pending_state; + } return code_editor->get_edit_state(); } void ScriptTextEditor::set_edit_state(const Variant &p_state) { - code_editor->set_edit_state(p_state); + if (editor_enabled) { + code_editor->set_edit_state(p_state); + } else { + // The editor is not fully initialized, so the state can't be loaded properly. + pending_state = p_state; + } Dictionary state = p_state; if (state.has("syntax_highlighter")) { diff --git a/editor/script/script_text_editor.h b/editor/script/script_text_editor.h index 7fa1ed4eff5..24b73d6deb6 100644 --- a/editor/script/script_text_editor.h +++ b/editor/script/script_text_editor.h @@ -62,6 +62,7 @@ class ScriptTextEditor : public ScriptEditorBase { RichTextLabel *errors_panel = nullptr; Ref