diff --git a/editor/gui/code_editor.cpp b/editor/gui/code_editor.cpp index 66ce17e594b..f164073c78f 100644 --- a/editor/gui/code_editor.cpp +++ b/editor/gui/code_editor.cpp @@ -1503,21 +1503,27 @@ void CodeTextEditor::set_edit_state(const Variant &p_state) { if (state.has("folded_lines")) { const PackedInt32Array folded_lines = state["folded_lines"]; for (const int &line : folded_lines) { - text_editor->fold_line(line); + if (line < text_editor->get_line_count()) { + text_editor->fold_line(line); + } } } if (state.has("breakpoints")) { const PackedInt32Array breakpoints = state["breakpoints"]; for (const int &line : breakpoints) { - text_editor->set_line_as_breakpoint(line, true); + if (line < text_editor->get_line_count()) { + text_editor->set_line_as_breakpoint(line, true); + } } } if (state.has("bookmarks")) { const PackedInt32Array bookmarks = state["bookmarks"]; for (const int &line : bookmarks) { - text_editor->set_line_as_bookmarked(line, true); + if (line < text_editor->get_line_count()) { + text_editor->set_line_as_bookmarked(line, true); + } } } diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp index cee5710da7d..cebbbeb24a8 100644 --- a/editor/script/script_editor_plugin.cpp +++ b/editor/script/script_editor_plugin.cpp @@ -41,6 +41,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/string/fuzzy_search.h" +#include "core/variant/dictionary.h" #include "core/version.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/script_editor_debugger.h" @@ -2546,7 +2547,9 @@ void ScriptEditor::_reload_scripts(bool p_refresh_only) { } if (TextEditorBase *teb = Object::cast_to(seb)) { + Dictionary state = teb->get_edit_state(); teb->reload_text(); + teb->set_edit_state(state); } }