Restore script editor state between sessions

This commit is contained in:
Paulb23 2019-04-13 12:43:35 +01:00
parent b7cf4c2050
commit 6ea253aa77
7 changed files with 93 additions and 13 deletions

View file

@ -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();
}