This commit is contained in:
jonyrock 2014-04-26 16:42:19 +04:00
parent 847ad3d519
commit a5e331c66f
2 changed files with 51 additions and 15 deletions

View file

@ -1072,8 +1072,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
cursor_set_line(selection.from_line); cursor_set_line(selection.from_line);
cursor_set_column(selection.from_column); cursor_set_column(selection.from_column);
_begin_compex_operation();
_remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
_insert_text_at_cursor(txt); _insert_text_at_cursor(txt);
_end_compex_operation();
selection.active=true; selection.active=true;
selection.from_column=sel_column; selection.from_column=sel_column;
selection.from_line=sel_line; selection.from_line=sel_line;
@ -1569,8 +1571,6 @@ void TextEdit::_post_shift_selection() {
/**** TEXT EDIT CORE API ****/ /**** TEXT EDIT CORE API ****/
void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) { void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) {
//save for undo... //save for undo...
@ -1677,14 +1677,12 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_lin
void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) { void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) {
if (!setting_text) if (!setting_text)
idle_detect->start(); idle_detect->start();
if (undo_enabled) { if (undo_enabled) {
_clear_redo(); _clear_redo();
} }
@ -2511,8 +2509,13 @@ 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); _do_text_op( undo_stack_pos->get(),true);
if(undo_stack_pos->get().chain_backward) {
do {
undo_stack_pos = undo_stack_pos->prev();
_do_text_op(undo_stack_pos->get(), true);
} while(!undo_stack_pos->get().chain_forward);
}
cursor_set_line(undo_stack_pos->get().from_line); cursor_set_line(undo_stack_pos->get().from_line);
cursor_set_column(undo_stack_pos->get().from_column); cursor_set_column(undo_stack_pos->get().from_column);
@ -2526,8 +2529,13 @@ 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);
_do_text_op( undo_stack_pos->get(),false); if(undo_stack_pos->get().chain_forward) {
do {
undo_stack_pos=undo_stack_pos->next();
_do_text_op(undo_stack_pos->get(), false);
} while(!undo_stack_pos->get().chain_backward);
}
cursor_set_line(undo_stack_pos->get().from_line); cursor_set_line(undo_stack_pos->get().from_line);
cursor_set_column(undo_stack_pos->get().from_column); cursor_set_column(undo_stack_pos->get().from_column);
undo_stack_pos=undo_stack_pos->next(); undo_stack_pos=undo_stack_pos->next();
@ -2539,19 +2547,42 @@ void TextEdit::clear_undo_history() {
saved_version=0; saved_version=0;
current_op.type=TextOperation::TYPE_NONE; current_op.type=TextOperation::TYPE_NONE;
undo_stack_pos=NULL; undo_stack_pos=NULL;
undo_stack.clear();; undo_stack.clear();
} }
void TextEdit::_begin_compex_operation() {
_push_current_op();
next_operation_is_complex=true;
}
void TextEdit::_end_compex_operation() {
_push_current_op();
ERR_FAIL_COND(undo_stack.size() == 0);
if(undo_stack.back()->get().chain_forward) {
undo_stack.back()->get().chain_forward=false;
return;
}
undo_stack.back()->get().chain_backward=true;
}
void TextEdit::_push_current_op() { void TextEdit::_push_current_op() {
if (current_op.type==TextOperation::TYPE_NONE) if (current_op.type==TextOperation::TYPE_NONE)
return; // do nothing return; // do nothing
if(next_operation_is_complex) {
current_op.chain_forward=true;
next_operation_is_complex=false;
}
undo_stack.push_back(current_op); undo_stack.push_back(current_op);
current_op.type=TextOperation::TYPE_NONE; current_op.type=TextOperation::TYPE_NONE;
current_op.text=""; current_op.text="";
current_op.chain_forward=false;
} }
@ -2957,6 +2988,7 @@ TextEdit::TextEdit() {
completion_line_ofs=0; completion_line_ofs=0;
tooltip_obj=NULL; tooltip_obj=NULL;
line_numbers=false; line_numbers=false;
next_operation_is_complex=false;
} }
TextEdit::~TextEdit(){ TextEdit::~TextEdit(){

View file

@ -219,6 +219,8 @@ class TextEdit : public Control {
StringName tooltip_func; StringName tooltip_func;
Variant tooltip_ud; Variant tooltip_ud;
bool next_operation_is_complex;
int get_visible_rows() const; int get_visible_rows() const;
int get_char_count(); int get_char_count();
@ -242,6 +244,8 @@ class TextEdit : public Control {
void _cursor_changed_emit(); void _cursor_changed_emit();
void _text_changed_emit(); void _text_changed_emit();
void _begin_compex_operation();
void _end_compex_operation();
void _push_current_op(); void _push_current_op();
/* super internal api, undo/redo builds on it */ /* super internal api, undo/redo builds on it */