diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-04-21 13:01:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-21 13:01:43 +0200 |
commit | 71bbe6eb01d1664340ea624aca36aa47c693981d (patch) | |
tree | 7fab2ac8f65a8d3190d4255d1ba22cbb52a8697f /editor/code_editor.cpp | |
parent | 7879968136828a6b98daab9ee4e8897eb8c26048 (diff) | |
parent | 6ea253aa776e03dc7174b289c6747cd8d0410245 (diff) | |
download | redot-engine-71bbe6eb01d1664340ea624aca36aa47c693981d.tar.gz |
Merge pull request #27979 from Paulb23/remember_script_state
Restore script editor state between sessions
Diffstat (limited to 'editor/code_editor.cpp')
-rw-r--r-- | editor/code_editor.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 134384c167..ec159ab173 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1180,17 +1180,57 @@ Variant CodeTextEditor::get_edit_state() { Dictionary state; state["scroll_position"] = text_editor->get_v_scroll(); + state["h_scroll_position"] = text_editor->get_h_scroll(); state["column"] = text_editor->cursor_get_column(); state["row"] = text_editor->cursor_get_line(); + state["selection"] = get_text_edit()->is_selection_active(); + if (get_text_edit()->is_selection_active()) { + state["selection_from_line"] = text_editor->get_selection_from_line(); + state["selection_from_column"] = text_editor->get_selection_from_column(); + state["selection_to_line"] = text_editor->get_selection_to_line(); + state["selection_to_column"] = text_editor->get_selection_to_column(); + } + + state["folded_lines"] = text_editor->get_folded_lines(); + state["breakpoints"] = text_editor->get_breakpoints_array(); + + state["syntax_highlighter"] = TTR("Standard"); + SyntaxHighlighter *syntax_highlighter = text_editor->_get_syntax_highlighting(); + if (syntax_highlighter) { + state["syntax_highlighter"] = syntax_highlighter->get_name(); + } + return state; } void CodeTextEditor::set_edit_state(const Variant &p_state) { Dictionary state = p_state; - text_editor->cursor_set_column(state["column"]); + + /* update the row first as it sets the column to 0 */ text_editor->cursor_set_line(state["row"]); + text_editor->cursor_set_column(state["column"]); text_editor->set_v_scroll(state["scroll_position"]); + text_editor->set_h_scroll(state["h_scroll_position"]); + + if (state.has("selection")) { + text_editor->select(state["selection_from_line"], state["selection_from_column"], state["selection_to_line"], state["selection_to_column"]); + } + + if (state.has("folded_lines")) { + Vector<int> folded_lines = state["folded_lines"]; + for (int i = 0; i < folded_lines.size(); i++) { + text_editor->fold_line(folded_lines[i]); + } + } + + if (state.has("breakpoints")) { + Array breakpoints = state["breakpoints"]; + for (int i = 0; i < breakpoints.size(); i++) { + text_editor->set_line_as_breakpoint(breakpoints[i], true); + } + } + text_editor->grab_focus(); } |