undo: when undoing a paste or an insertion, remove an added magic line

When something is pasted or inserted onto the final, empty line of a
buffer, an automatic new magic line is created after it, when needed.
When this paste or insertion is undone, the added magic line should
also be removed again.

This fixes https://savannah.gnu.org/bugs/?57808.

Bug existed since the undo capabilities were added,
since before version 2.3.0.
This commit is contained in:
Benno Schulenberg 2020-02-14 13:43:00 +01:00
parent 68ca1732b8
commit a0506a15ee

View File

@ -481,9 +481,10 @@ void undo_cut(undostruct *u)
copy_from_buffer(u->cutbuffer);
/* If the final line was originally cut, remove the extra magic line. */
/* If originally the last line was cut too, remove an extra magic line. */
if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES) &&
openfile->current != openfile->filebot)
openfile->filebot != openfile->current &&
openfile->filebot->prev->data[0] == '\0')
remove_magicline();
if (!(u->xflags & WAS_MARKED_FORWARD) && u->type != PASTE)
@ -618,6 +619,9 @@ void do_undo(void)
case PASTE:
undidmsg = _("paste");
undo_paste(u);
if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES) &&
openfile->filebot != openfile->current)
remove_magicline();
break;
case INSERT:
undidmsg = _("insertion");
@ -629,6 +633,9 @@ void do_undo(void)
cut_marked(NULL);
u->cutbuffer = cutbuffer;
cutbuffer = oldcutbuffer;
if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES) &&
openfile->filebot != openfile->current)
remove_magicline();
break;
case COUPLE_BEGIN:
undidmsg = u->strdata;
@ -1216,10 +1223,14 @@ void add_undo(undo_type action, const char *message)
}
break;
case PASTE:
if (openfile->current == openfile->filebot)
u->xflags |= WAS_FINAL_LINE;
u->cutbuffer = copy_buffer(cutbuffer);
u->lineno += cutbottom->lineno - cutbuffer->lineno;
break;
case INSERT:
if (openfile->current == openfile->filebot)
u->xflags |= WAS_FINAL_LINE;
break;
case COUPLE_BEGIN:
u->mark_begin_lineno = openfile->current_y;