--- src/text.c (revision 5238) +++ src/text.c (working copy) @@ -501,6 +501,10 @@ #endif /* !DISABLE_WRAPPING */ case JOIN: undidmsg = _("line join"); + + if (ISSET(NO_NEWLINES) || f->next != openfile->filebot || + openfile->filebot->data[0] != '\0' || u->strdata[0] != '\0') + { t = make_new_node(f); t->data = mallocstrcpy(NULL, u->strdata); data = mallocstrncpy(NULL, f->data, u->mark_begin_x + 1); @@ -510,6 +514,20 @@ splice_node(f, t, f->next); if (f == openfile->filebot) openfile->filebot = t; + } + else{ + undo *u2 = u->next; + while (u2 != NULL && u2->type == JOIN && u2->strdata[0] == '\0') + { //remove the undo from the list and free it; + u->next = u2->next; + if (u2->strdata != NULL) + free(u2->strdata); + if (u2->cutbuffer) + free_filestruct(u2->cutbuffer); + free(u2); + u2 = u->next; + } + } goto_line_posx(u->lineno, u->begin); break; case CUT_EOF: