--- src/text.c (revision 5245) +++ src/text.c (working copy) @@ -439,6 +439,16 @@ cutbottom = oldcutbottom; } + +void free_undo(undo *u2 ) +{ + if (u2->strdata != NULL) + free(u2->strdata); + if (u2->cutbuffer) + free_filestruct(u2->cutbuffer); + free(u2); +} + /* Undo the last thing(s) we did. */ void do_undo(void) { @@ -501,6 +511,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 +524,16 @@ 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; + free_undo(u2); + u2 = u->next; + } + } goto_line_posx(u->lineno, u->begin); break; case CUT_EOF: @@ -885,11 +909,7 @@ while (fs->undotop != NULL && fs->undotop != fs->current_undo) { undo *u2 = fs->undotop; fs->undotop = fs->undotop->next; - if (u2->strdata != NULL) - free(u2->strdata); - if (u2->cutbuffer) - free_filestruct(u2->cutbuffer); - free(u2); + free_undo(u2); } /* Allocate and initialize a new undo type. */