Merge pull request #52185 from Paulb23/nested-complex-ops
Allow nested complex ops in TextEdit
This commit is contained in:
commit
d039f4af14
2 changed files with 13 additions and 1 deletions
|
@ -2731,6 +2731,8 @@ void TextEdit::insert_line_at(int p_at, const String &p_text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEdit::insert_text_at_caret(const String &p_text) {
|
void TextEdit::insert_text_at_caret(const String &p_text) {
|
||||||
|
begin_complex_operation();
|
||||||
|
|
||||||
delete_selection();
|
delete_selection();
|
||||||
|
|
||||||
int new_column, new_line;
|
int new_column, new_line;
|
||||||
|
@ -2740,6 +2742,8 @@ void TextEdit::insert_text_at_caret(const String &p_text) {
|
||||||
set_caret_line(new_line, false);
|
set_caret_line(new_line, false);
|
||||||
set_caret_column(new_column);
|
set_caret_column(new_column);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
end_complex_operation();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEdit::remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
|
void TextEdit::remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
|
||||||
|
@ -3024,13 +3028,20 @@ void TextEdit::menu_option(int p_option) {
|
||||||
/* Versioning */
|
/* Versioning */
|
||||||
void TextEdit::begin_complex_operation() {
|
void TextEdit::begin_complex_operation() {
|
||||||
_push_current_op();
|
_push_current_op();
|
||||||
|
if (complex_operation_count == 0) {
|
||||||
next_operation_is_complex = true;
|
next_operation_is_complex = true;
|
||||||
|
}
|
||||||
|
complex_operation_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEdit::end_complex_operation() {
|
void TextEdit::end_complex_operation() {
|
||||||
_push_current_op();
|
_push_current_op();
|
||||||
ERR_FAIL_COND(undo_stack.size() == 0);
|
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) {
|
if (undo_stack.back()->get().chain_forward) {
|
||||||
undo_stack.back()->get().chain_forward = false;
|
undo_stack.back()->get().chain_forward = false;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -304,6 +304,7 @@ private:
|
||||||
bool undo_enabled = true;
|
bool undo_enabled = true;
|
||||||
int undo_stack_max_size = 50;
|
int undo_stack_max_size = 50;
|
||||||
|
|
||||||
|
int complex_operation_count = 0;
|
||||||
bool next_operation_is_complex = false;
|
bool next_operation_is_complex = false;
|
||||||
|
|
||||||
TextOperation current_op;
|
TextOperation current_op;
|
||||||
|
|
Loading…
Reference in a new issue