Undo and redo commands on text editor now affect internal version which fixes inconsistent file saving validation.

(cherry picked from commit b2e471fd7c)
This commit is contained in:
Saracen 2016-03-13 20:08:12 +00:00 committed by Rémi Verschelde
parent 763b29ed18
commit d0151daa69
2 changed files with 19 additions and 6 deletions

View File

@ -2494,6 +2494,7 @@ void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_e
//see if it shold just be set as current op //see if it shold just be set as current op
if (current_op.type!=op.type) { if (current_op.type!=op.type) {
op.prev_version = get_version();
_push_current_op(); _push_current_op();
current_op=op; current_op=op;
@ -2501,6 +2502,7 @@ void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_e
} }
//see if it can be merged //see if it can be merged
if (current_op.to_line!=p_line || current_op.to_column!=p_char) { if (current_op.to_line!=p_line || current_op.to_column!=p_char) {
op.prev_version = get_version();
_push_current_op(); _push_current_op();
current_op=op; current_op=op;
return; //set as current op, return return; //set as current op, return
@ -2544,6 +2546,7 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int
//see if it shold just be set as current op //see if it shold just be set as current op
if (current_op.type!=op.type) { if (current_op.type!=op.type) {
op.prev_version = get_version();
_push_current_op(); _push_current_op();
current_op=op; current_op=op;
return; //set as current op, return return; //set as current op, return
@ -2564,6 +2567,7 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int
//return; //update current op //return; //update current op
} }
op.prev_version = get_version();
_push_current_op(); _push_current_op();
current_op=op; current_op=op;
@ -3397,11 +3401,15 @@ void TextEdit::undo() {
else else
undo_stack_pos=undo_stack_pos->prev(); undo_stack_pos=undo_stack_pos->prev();
_do_text_op( undo_stack_pos->get(),true); TextOperation op = undo_stack_pos->get();
_do_text_op(op, true);
current_op.version=op.prev_version;
if(undo_stack_pos->get().chain_backward) { if(undo_stack_pos->get().chain_backward) {
do { do {
undo_stack_pos = undo_stack_pos->prev(); undo_stack_pos = undo_stack_pos->prev();
_do_text_op(undo_stack_pos->get(), true); op = undo_stack_pos->get();
_do_text_op(op, true);
current_op.version = op.prev_version;
} while(!undo_stack_pos->get().chain_forward); } while(!undo_stack_pos->get().chain_forward);
} }
@ -3417,15 +3425,19 @@ void TextEdit::redo() {
if (undo_stack_pos==NULL) if (undo_stack_pos==NULL)
return; //nothing to do. return; //nothing to do.
_do_text_op(undo_stack_pos->get(), false); TextOperation op = undo_stack_pos->get();
_do_text_op(op, false);
current_op.version = op.version;
if(undo_stack_pos->get().chain_forward) { if(undo_stack_pos->get().chain_forward) {
do { do {
undo_stack_pos=undo_stack_pos->next(); undo_stack_pos=undo_stack_pos->next();
_do_text_op(undo_stack_pos->get(), false); op = undo_stack_pos->get();
_do_text_op(op, false);
current_op.version = op.version;
} while(!undo_stack_pos->get().chain_backward); } while(!undo_stack_pos->get().chain_backward);
} }
cursor_set_line(undo_stack_pos->get().from_line); cursor_set_line(undo_stack_pos->get().to_line);
cursor_set_column(undo_stack_pos->get().from_column); cursor_set_column(undo_stack_pos->get().to_column);
undo_stack_pos=undo_stack_pos->next(); undo_stack_pos=undo_stack_pos->next();
update(); update();
} }

View File

@ -156,6 +156,7 @@ class TextEdit : public Control {
int from_line,from_column; int from_line,from_column;
int to_line, to_column; int to_line, to_column;
String text; String text;
uint32_t prev_version;
uint32_t version; uint32_t version;
bool chain_forward; bool chain_forward;
bool chain_backward; bool chain_backward;