From 4b814698bd6c8040ea89b7ac07f211bd2208f129 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 31 Mar 2020 19:08:15 +0200 Subject: [PATCH] copying: with --nonewlines, don't add a final newline to the cutbuffer This fixes https://savannah.gnu.org/bugs/?58086. Bug existed since commit f52b6cf1 from yesterday. --- src/cut.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cut.c b/src/cut.c index 9d604b83..5236d7af 100644 --- a/src/cut.c +++ b/src/cut.c @@ -564,6 +564,7 @@ void copy_marked_region(void) void copy_text(void) { bool at_eol = (openfile->current->data[openfile->current_x] == '\0'); + bool on_last_line = (openfile->current->next == NULL); linestruct *addition; if (openfile->mark || openfile->last_action != COPY || !keep_cutbuffer) { @@ -610,11 +611,19 @@ void copy_text(void) } else { addition->data = copy_of(openfile->current->data); - if (cutbuffer == NULL) { + if (cutbuffer == NULL && on_last_line && ISSET(NO_NEWLINES)) { + cutbuffer = addition; + cutbottom = addition; + } else if (cutbuffer == NULL) { cutbuffer = addition; cutbottom = make_new_node(cutbuffer); cutbottom->data = copy_of(""); cutbuffer->next = cutbottom; + } else if (on_last_line && ISSET(NO_NEWLINES)) { + addition->prev = cutbottom->prev; + addition->prev->next = addition; + delete_node(cutbottom); + cutbottom = addition; } else { addition->prev = cutbottom->prev; addition->prev->next = addition;