From: Benno Schulenberg Date: Mon, 30 Nov 2015 16:21:51 +0000 (+0000) Subject: Storing and retrieving the correct file size before and after an action. X-Git-Tag: v2.5.0~27 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=66e21416afe77049bbd6956f27f9872a84ae8bca;p=nano.git Storing and retrieving the correct file size before and after an action. This fixes Savannah bug #45523. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5456 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 9ba5f935..6f6628c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ and NONEWLINES is set, there is no next line at which to put the cutting point for a redo. So put it at the very end of the cut. This fixes Savannah bug #46541. + * src/text.c (add_undo, update_undo, do_undo, do_redo), src/nano.h: + Store and retrieve the correct file size before and after an action. + This fixes Savannah bug #45523. 2015-11-29 Benno Schulenberg * src/color.c (reset_multis): Evaluate correctly whether to reset diff --git a/src/nano.h b/src/nano.h index b2604a17..e9293e18 100644 --- a/src/nano.h +++ b/src/nano.h @@ -329,6 +329,10 @@ typedef struct undo { /* Where did this action begin or end. */ char *strdata; /* String type data we will use for copying the affected line back. */ + size_t wassize; + /* The file size before the action. */ + size_t newsize; + /* The file size after the action. */ int xflags; /* Some flag data we need. */ diff --git a/src/text.c b/src/text.c index ff9872b7..2a2a5161 100644 --- a/src/text.c +++ b/src/text.c @@ -611,6 +611,7 @@ void do_undo(void) openfile->current_undo = openfile->current_undo->next; openfile->last_action = OTHER; openfile->placewewant = xplustabs(); + openfile->totsize = u->wassize; set_modified(); } @@ -748,6 +749,7 @@ void do_redo(void) openfile->current_undo = u; openfile->last_action = OTHER; openfile->placewewant = xplustabs(); + openfile->totsize = u->newsize; set_modified(); } #endif /* !NANO_TINY */ @@ -957,12 +959,14 @@ void add_undo(undo_type action) u->mark_begin_lineno = openfile->current->lineno; u->mark_begin_x = openfile->current_x; u->mark_set = FALSE; + u->wassize = openfile->totsize; u->xflags = 0; switch (u->type) { /* We need to start copying data into the undo buffer * or we won't be able to restore it later. */ case ADD: + u->wassize--; break; case BACK: /* If the next line is the magic line, don't ever undo this @@ -1065,6 +1069,8 @@ fprintf(stderr, " >> Updating... action = %d, openfile->last_action = %d, openf assert(openfile->undotop != NULL); u = openfile->undotop; + u->newsize = openfile->totsize; + switch (u->type) { case ADD: { #ifdef DEBUG