From 329b82d2840466dbce9298122c352ad35fdd27f6 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 1 Jan 2019 12:28:27 +0100 Subject: [PATCH] undo: set the correct file size for a redo of a character deletion The reduced file size should be stored not just when joining two lines but also when simply a character in the middle of a line is deleted. This fixes https://savannah.gnu.org/bugs/?55352. Bug existed since version 2.5.0, commit 66e21416. --- src/text.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/text.c b/src/text.c index 3c396be5..4357216e 100644 --- a/src/text.c +++ b/src/text.c @@ -116,8 +116,6 @@ void do_deletion(undo_type action) openfile->mark_x > openfile->current_x) openfile->mark_x -= char_len; #endif - /* Adjust the file size. */ - openfile->totsize--; } else if (openfile->current != openfile->filebot) { /* We're at the end of a line and not at the end of the file: join * this line with the next. */ @@ -141,13 +139,7 @@ void do_deletion(undo_type action) strlen(openfile->current->data) + strlen(joining->data) + 1); strcat(openfile->current->data, joining->data); - /* Adjust the file size. */ - openfile->totsize--; - #ifndef NANO_TINY - /* Remember the new file size for a possible redo. */ - openfile->current_undo->newsize = openfile->totsize; - /* Adjust the mark if it was on the line that was "eaten". */ if (openfile->mark == joining) { openfile->mark = openfile->current; @@ -163,7 +155,11 @@ void do_deletion(undo_type action) /* We're at the end-of-file: nothing to do. */ return; + /* Adjust the file size, and remember it for a possible redo. */ + openfile->totsize--; #ifndef NANO_TINY + openfile->current_undo->newsize = openfile->totsize; + /* If the number of screen rows that a softwrapped line occupies * has changed, we need a full refresh. */ if (ISSET(SOFTWRAP) && refresh_needed == FALSE &&