commit 82373d85f95d2210dfc40ae78ecc44fd5347d5d3
parent c32a58a826a40c1b90a61ee5ab68ced25cb190f2
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 17 Jun 2015 10:41:57 +0000
Preventing the addition of an extra newline when undoing a Backspace or Delete
at the tail of the file while nonewlines is not set.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5250 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,12 @@
+2015-06-17 Benno Schulenberg <bensberg@justemail.net>
+ * src/text.c (do_undo, add_undo): When undoing a Backspace at the tail
+ of the file and nonewlines is not set, then don't add another newline
+ but just reposition the cursor. Also, when doing a Delete at the tail
+ of the file, don't add a superfluous undo structure. This prevents
+ the appearance of an extra newline when undoing the Backspace/Delete.
+ Patch partially by Mark Majeres. The problem was first reported in
+ https://lists.gnu.org/archive/html/nano-devel/2015-06/msg00003.html.
+
2015-06-14 Benno Schulenberg <bensberg@justemail.net>
* src/winio.c (edit_draw): Add some debugging code to track which
multidata codes (for multiline regexes) get assigned to which lines.
diff --git a/src/text.c b/src/text.c
@@ -501,6 +501,10 @@ void do_undo(void)
#endif /* !DISABLE_WRAPPING */
case JOIN:
undidmsg = _("line join");
+ /* When the join was done by a Backspace at the tail of the file,
+ * don't actually add another line; just position the cursor. */
+ if (f->next != openfile->filebot || u->xflags != UNdel_backspace ||
+ ISSET(NO_NEWLINES)) {
t = make_new_node(f);
t->data = mallocstrcpy(NULL, u->strdata);
data = mallocstrncpy(NULL, f->data, u->mark_begin_x + 1);
@@ -510,6 +514,7 @@ void do_undo(void)
splice_node(f, t, f->next);
if (f == openfile->filebot)
openfile->filebot = t;
+ }
goto_line_posx(u->lineno, u->begin);
break;
case CUT_EOF:
@@ -880,6 +885,11 @@ void add_undo(undo_type current_action)
((current_action == CUT && u->type == CUT && !u->mark_set && keeping_cutbuffer()) ||
(current_action == ADD && u->type == ADD && u->mark_begin_x == fs->current_x)))
return;
+ /* When trying to delete the final newline, don't add an undo for it. */
+ if (current_action == DEL && openfile->current->next == openfile->filebot &&
+ openfile->current->data[openfile->current_x] == '\0' &&
+ openfile->current_x != 0 && !ISSET(NO_NEWLINES))
+ return;
/* Blow away the old undo stack if we are starting from the middle. */
while (fs->undotop != NULL && fs->undotop != fs->current_undo) {
@@ -924,6 +934,7 @@ void add_undo(undo_type current_action)
case ADD:
break;
case BACK:
+ u->xflags = UNdel_backspace;
case DEL:
if (u->begin != strlen(fs->current->data)) {
char *char_buf = charalloc(mb_cur_max() + 1);