diff -rupN original/src/text.c new/src/text.c --- original/src/text.c 2013-03-21 06:17:24.000000000 -0700 +++ new/src/text.c 2014-03-25 19:44:03.780833139 -0700 @@ -846,7 +846,6 @@ void add_undo(undo_type current_action) undo *u; char *data; openfilestruct *fs = openfile; - static undo *last_cutu = NULL; /* Last thing we cut to set up the undo for uncut */ ssize_t wrap_loc; /* For calculating split beginning */ if (!ISSET(UNDOABLE)) @@ -939,15 +938,25 @@ void add_undo(undo_type current_action) u->mark_begin_x = openfile->mark_begin_x; } u->to_end = (ISSET(CUT_TO_END)) ? TRUE : FALSE; - last_cutu = u; break; case UNCUT: - if (!last_cutu) + if (!cutbuffer) statusbar(_("Internal error: can't setup uncut. Please save your work.")); - else if (last_cutu->type == CUT) { - u->cutbuffer = last_cutu->cutbuffer; - u->cutbottom = last_cutu->cutbottom; - } + else{ + if (u->cutbuffer) free(u->cutbuffer); + u->cutbuffer = copy_filestruct(cutbuffer); + + u->mark_begin_lineno = u->lineno + cutbottom->lineno - cutbuffer->lineno; + filestruct *fs_buff = cutbuffer; + if(fs_buff->lineno == cutbottom->lineno) + u->mark_begin_x += u->begin; + else + for (; fs_buff->lineno != cutbottom->lineno && fs_buff->next != NULL; fs_buff = fs_buff->next); + assert(fs_buff->next != NULL); + u->mark_begin_x += get_totsize(fs_buff,cutbottom); + + u->mark_set = TRUE; + } break; case ENTER: break;