Commit 91a1862e authored by Chris Allegretta's avatar Chris Allegretta
Browse files

Add undoing argument to do_cut_text as we don't want to be messing around with...

Add undoing argument to do_cut_text as we don't want to be messing around with the undo contents when we're in the 
middle of an undo.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4285 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 28 additions and 12 deletions
+28 -12
...@@ -113,7 +113,7 @@ void cut_to_eof(void) ...@@ -113,7 +113,7 @@ void cut_to_eof(void)
* position to the end of the file into the cutbuffer. */ * position to the end of the file into the cutbuffer. */
void do_cut_text( void do_cut_text(
#ifndef NANO_TINY #ifndef NANO_TINY
bool copy_text, bool cut_till_end bool copy_text, bool cut_till_end, bool undoing
#else #else
void void
#endif #endif
...@@ -204,7 +204,7 @@ void do_cut_text( ...@@ -204,7 +204,7 @@ void do_cut_text(
* disturbing the text. */ * disturbing the text. */
if (!old_no_newlines) if (!old_no_newlines)
UNSET(NO_NEWLINES); UNSET(NO_NEWLINES);
} else } else if (!undoing)
update_undo(CUT, openfile); update_undo(CUT, openfile);
#endif #endif
/* Leave the text in the cutbuffer, and mark the file as /* Leave the text in the cutbuffer, and mark the file as
...@@ -226,7 +226,7 @@ void do_cut_text_void(void) ...@@ -226,7 +226,7 @@ void do_cut_text_void(void)
add_undo(CUT, openfile); add_undo(CUT, openfile);
do_cut_text( do_cut_text(
#ifndef NANO_TINY #ifndef NANO_TINY
FALSE, FALSE FALSE, FALSE, FALSE
#endif #endif
); );
} }
...@@ -236,14 +236,14 @@ void do_cut_text_void(void) ...@@ -236,14 +236,14 @@ void do_cut_text_void(void)
* back into the filestruct afterward. */ * back into the filestruct afterward. */
void do_copy_text(void) void do_copy_text(void)
{ {
do_cut_text(TRUE, FALSE); do_cut_text(TRUE, FALSE, FALSE);
} }
/* Cut from the current cursor position to the end of the file. */ /* Cut from the current cursor position to the end of the file. */
void do_cut_till_end(void) void do_cut_till_end(void)
{ {
add_undo(CUTTOEND, openfile); add_undo(CUTTOEND, openfile);
do_cut_text(FALSE, TRUE); do_cut_text(FALSE, TRUE, FALSE);
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
......
...@@ -239,7 +239,7 @@ void cut_to_eof(void); ...@@ -239,7 +239,7 @@ void cut_to_eof(void);
#endif #endif
void do_cut_text( void do_cut_text(
#ifndef NANO_TINY #ifndef NANO_TINY
bool copy_text, bool cut_till_end bool copy_text, bool cut_till_end, bool undoing
#else #else
void void
#endif #endif
......
...@@ -554,7 +554,7 @@ void do_redo(void) ...@@ -554,7 +554,7 @@ void do_redo(void)
openfile->mark_begin = t; openfile->mark_begin = t;
} }
openfile->mark_begin_x = u->mark_begin_x; openfile->mark_begin_x = u->mark_begin_x;
do_cut_text(FALSE, u->to_end); do_cut_text(FALSE, u->to_end, TRUE);
openfile->mark_set = FALSE; openfile->mark_set = FALSE;
openfile->mark_begin = NULL; openfile->mark_begin = NULL;
openfile->mark_begin_x = 0; openfile->mark_begin_x = 0;
...@@ -734,11 +734,17 @@ void add_undo(undo_type current_action, openfilestruct *fs) ...@@ -734,11 +734,17 @@ void add_undo(undo_type current_action, openfilestruct *fs)
char *data; char *data;
/* Blow away the old undo stack if we are starting from the middle */ /* Blow away the old undo stack if we are starting from the middle */
while (fs->undotop != fs->current_undo) { while (fs->undotop != NULL && fs->undotop != fs->current_undo) {
undo *tmp = fs->undotop; undo *u2 = fs->undotop;
fs->undotop = fs->undotop->next; fs->undotop = fs->undotop->next;
free(tmp->strdata); if (u2->strdata != NULL)
free(tmp); free(u2->strdata);
while (u2->cutbuffer != NULL) {
filestruct *f2 = u2->cutbuffer->next;
u2->cutbuffer = u2->cutbuffer->next;
free(f2);
}
free(u2);
} }
u->type = current_action; u->type = current_action;
...@@ -747,6 +753,10 @@ void add_undo(undo_type current_action, openfilestruct *fs) ...@@ -747,6 +753,10 @@ void add_undo(undo_type current_action, openfilestruct *fs)
u->next = fs->undotop; u->next = fs->undotop;
fs->undotop = u; fs->undotop = u;
fs->current_undo = u; fs->current_undo = u;
u->strdata = NULL;
u->cutbuffer = NULL;
u->cutbottom = NULL;
u->xflags = 0;
switch (u->type) { switch (u->type) {
/* We need to start copying data into the undo buffer or we wont be able /* We need to start copying data into the undo buffer or we wont be able
...@@ -808,11 +818,17 @@ void update_undo(undo_type action, openfilestruct *fs) ...@@ -808,11 +818,17 @@ void update_undo(undo_type action, openfilestruct *fs)
char *data; char *data;
int len = 0; int len = 0;
#ifdef DEBUG
fprintf(stderr, "action = %d, fs->last_action = %d, openfile->current->lineno = %d, fs->current_undo->lineno = %d\n",
action, fs->last_action, openfile->current->lineno, fs->current_undo->lineno);
#endif
/* Change to an add if we're not using the same undo struct /* Change to an add if we're not using the same undo struct
that we should be using */ that we should be using */
if (action != fs->last_action if (action != fs->last_action
|| (action != CUT && action != CUTTOEND || (action != CUT && action != CUTTOEND
&& openfile->current->lineno != fs->undotop->lineno)) { && openfile->current->lineno != fs->current_undo->lineno)) {
add_undo(action, fs); add_undo(action, fs);
return; return;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment