nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit a0506a15eea1cf72e87f9524c0709d362af4473f
parent 68ca1732b8eecb1112ff0635560ad67b00844deb
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 14 Feb 2020 13:43:00 +0100

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.

Diffstat:
Msrc/text.c | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -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;