File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,11 @@ void ScriptTextEditor::enable_editor(Control *p_shortcut_context) {
184184
185185 _validate_script ();
186186
187+ if (pending_state != Variant ()) {
188+ code_editor->set_edit_state (pending_state);
189+ pending_state = Variant ();
190+ }
191+
187192 if (p_shortcut_context) {
188193 for (int i = 0 ; i < edit_hb->get_child_count (); ++i) {
189194 Control *c = cast_to<Control>(edit_hb->get_child (i));
@@ -704,11 +709,19 @@ bool ScriptTextEditor::is_unsaved() {
704709}
705710
706711Variant ScriptTextEditor::get_edit_state () {
712+ if (pending_state != Variant ()) {
713+ return pending_state;
714+ }
707715 return code_editor->get_edit_state ();
708716}
709717
710718void ScriptTextEditor::set_edit_state (const Variant &p_state) {
711- code_editor->set_edit_state (p_state);
719+ if (editor_enabled) {
720+ code_editor->set_edit_state (p_state);
721+ } else {
722+ // The editor is not fully initialized, so the state can't be loaded properly.
723+ pending_state = p_state;
724+ }
712725
713726 Dictionary state = p_state;
714727 if (state.has (" syntax_highlighter" )) {
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ class ScriptTextEditor : public ScriptEditorBase {
6262 RichTextLabel *errors_panel = nullptr ;
6363
6464 Ref<Script> script;
65+ Variant pending_state;
6566 bool script_is_valid = false ;
6667 bool editor_enabled = false ;
6768
You can’t perform that action at this time.
0 commit comments