Allow basic multi-^K cuts to be redone properly. Code getting uglier by the second.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4288 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2008-08-01 07:29:06 +00:00
parent 8f76112084
commit d31ddb789f
2 changed files with 33 additions and 3 deletions

View File

@ -274,7 +274,8 @@ typedef struct undo {
/* copy copy copy */ /* copy copy copy */
ssize_t mark_begin_x; ssize_t mark_begin_x;
/* Another shadow variable */ /* Another shadow variable */
ssize_t linescut;
/* How many lines we cut on a straight non-marked non-to-end cut */
struct undo *next; struct undo *next;
} undo; } undo;

View File

@ -443,12 +443,17 @@ void do_undo(void)
case CUTTOEND: case CUTTOEND:
undidmsg = _("text cut"); undidmsg = _("text cut");
cutbuffer = copy_filestruct(u->cutbuffer); cutbuffer = copy_filestruct(u->cutbuffer);
/* Compute cutbottom for the uncut using out copy */
for (cutbottom = cutbuffer; cutbottom->next != NULL; cutbottom = cutbottom->next) for (cutbottom = cutbuffer; cutbottom->next != NULL; cutbottom = cutbottom->next)
; ;
/* Get to where we need to uncut from */
if (u->mark_set && u->mark_begin_lineno < u->lineno) if (u->mark_set && u->mark_begin_lineno < u->lineno)
do_gotolinecolumn(u->mark_begin_lineno, u->mark_begin_x+1, FALSE, FALSE, FALSE, FALSE); do_gotolinecolumn(u->mark_begin_lineno, u->mark_begin_x+1, FALSE, FALSE, FALSE, FALSE);
else else
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE); do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
do_uncut_text(); do_uncut_text();
free_filestruct(cutbuffer); free_filestruct(cutbuffer);
cutbuffer = NULL; cutbuffer = NULL;
@ -548,19 +553,39 @@ void do_redo(void)
undidmsg = _("line cut"); undidmsg = _("line cut");
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE); do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
openfile->mark_set = u->mark_set; openfile->mark_set = u->mark_set;
t = cutbuffer; if (cutbuffer)
free(cutbuffer);
cutbuffer = NULL; cutbuffer = NULL;
/* Move ahead the same # lines we had if a marked cut */
if (u->mark_set) { if (u->mark_set) {
for (i = 1, t = openfile->fileage; i != u->mark_begin_lineno; i++) for (i = 1, t = openfile->fileage; i != u->mark_begin_lineno; i++)
t = t->next; t = t->next;
openfile->mark_begin = t; openfile->mark_begin = t;
} else if (!u->to_end) {
/* Here we have a regular old potentially multi-line ^K cut. We'll
need to trick nano into thinking it's a marked cut to cut more
than one line again */
#ifdef DEBUG
fprintf(stderr, "Undoing multi-^K cut, u->linescut = %d\n", u->linescut);
#endif
for (i = 0, t = openfile->current; i < u->linescut; i++) {
#ifdef DEBUG
fprintf(stderr, "Advancing, lineno = %d, data = \"%s\"\n", t->lineno, t->data);
#endif
t = t->next;
} }
openfile->mark_begin = t;
openfile->mark_begin_x = 0;
openfile->mark_set = TRUE;
}
openfile->mark_begin_x = u->mark_begin_x; openfile->mark_begin_x = u->mark_begin_x;
do_cut_text(FALSE, u->to_end, TRUE); 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;
cutbuffer = t;
edit_refresh(); edit_refresh();
break; break;
default: default:
@ -766,6 +791,9 @@ void add_undo(undo_type current_action, openfilestruct *fs)
u->strdata = NULL; u->strdata = NULL;
u->cutbuffer = NULL; u->cutbuffer = NULL;
u->cutbottom = NULL; u->cutbottom = NULL;
u->mark_begin_lineno = 0;
u->mark_begin_x = 0;
u->linescut = 0;
u->xflags = 0; u->xflags = 0;
switch (u->type) { switch (u->type) {
@ -908,6 +936,7 @@ void update_undo(undo_type action, openfilestruct *fs)
free(u->cutbuffer); free(u->cutbuffer);
u->cutbuffer = copy_filestruct(cutbuffer); u->cutbuffer = copy_filestruct(cutbuffer);
u->cutbottom = cutbottom; u->cutbottom = cutbottom;
u->linescut++;
break; break;
case SPLIT: case SPLIT:
case UNSPLIT: case UNSPLIT: