diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2017-08-22 19:52:17 +0200 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2017-08-22 19:52:17 +0200 |
commit | c2a1f3b8146f939c837b8997b7f6673fac7508d8 (patch) | |
tree | fcf154c942a3e384593026a557e0269deac94088 | |
parent | 294e912a843cde241f9abf619f5d40df9ef6ef9f (diff) |
Add ability to undo auto-indent
Closes #10420.
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 19de027287..e69fa6da88 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -977,16 +977,27 @@ void ScriptTextEditor::_edit_option(int p_op) { Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; + + te->begin_complex_operation(); int begin, end; if (te->is_selection_active()) { begin = te->get_selection_from_line(); end = te->get_selection_to_line(); + // ignore if the cursor is not past the first column + if (te->get_selection_to_column() == 0) { + end--; + } } else { begin = 0; end = te->get_line_count() - 1; } scr->get_language()->auto_indent_code(text, begin, end); - te->set_text(text); + Vector<String> lines = text.split("\n"); + for (int i = begin; i <= end; ++i) { + te->set_line(i, lines[i]); + } + + te->end_complex_operation(); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { |