diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2021-08-28 12:23:51 +0100 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2021-08-28 12:49:55 +0100 |
commit | c5d7ae7920605ef5753f1838e83c015df339929a (patch) | |
tree | c724bdd79e1d76bc989d6e28045a4b9b49dbb4ee | |
parent | dcf2d09231c03c444cf5374b4d250f327f1333e4 (diff) |
Allow nested complex ops in TextEdit
-rw-r--r-- | scene/gui/text_edit.cpp | 13 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index a731f80741..560ea5af3c 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2644,6 +2644,8 @@ void TextEdit::insert_line_at(int p_at, const String &p_text) { } void TextEdit::insert_text_at_caret(const String &p_text) { + begin_complex_operation(); + delete_selection(); int new_column, new_line; @@ -2653,6 +2655,8 @@ void TextEdit::insert_text_at_caret(const String &p_text) { set_caret_line(new_line, false); set_caret_column(new_column); update(); + + end_complex_operation(); } void TextEdit::remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) { @@ -2937,13 +2941,20 @@ void TextEdit::menu_option(int p_option) { /* Versioning */ void TextEdit::begin_complex_operation() { _push_current_op(); - next_operation_is_complex = true; + if (complex_operation_count == 0) { + next_operation_is_complex = true; + } + complex_operation_count++; } void TextEdit::end_complex_operation() { _push_current_op(); ERR_FAIL_COND(undo_stack.size() == 0); + complex_operation_count = MAX(complex_operation_count - 1, 0); + if (complex_operation_count > 0) { + return; + } if (undo_stack.back()->get().chain_forward) { undo_stack.back()->get().chain_forward = false; return; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index ced03e19d0..a9d5f8ec3b 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -289,6 +289,7 @@ private: bool undo_enabled = true; int undo_stack_max_size = 50; + int complex_operation_count = 0; bool next_operation_is_complex = false; TextOperation current_op; |