Merge pull request #10558 from RandomShaper/undo-after-auto-indent
Add ability to undo auto-indent
This commit is contained in:
commit
0c3b90ef6b
|
@ -977,16 +977,27 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
||||||
Ref<Script> scr = get_edited_script();
|
Ref<Script> scr = get_edited_script();
|
||||||
if (scr.is_null())
|
if (scr.is_null())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
te->begin_complex_operation();
|
||||||
int begin, end;
|
int begin, end;
|
||||||
if (te->is_selection_active()) {
|
if (te->is_selection_active()) {
|
||||||
begin = te->get_selection_from_line();
|
begin = te->get_selection_from_line();
|
||||||
end = te->get_selection_to_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 {
|
} else {
|
||||||
begin = 0;
|
begin = 0;
|
||||||
end = te->get_line_count() - 1;
|
end = te->get_line_count() - 1;
|
||||||
}
|
}
|
||||||
scr->get_language()->auto_indent_code(text, begin, end);
|
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;
|
} break;
|
||||||
case EDIT_TRIM_TRAILING_WHITESAPCE: {
|
case EDIT_TRIM_TRAILING_WHITESAPCE: {
|
||||||
|
|
Loading…
Reference in New Issue