Index: src/nano.c =================================================================== --- src/nano.c (revision 5049) +++ src/nano.c (working copy) @@ -1703,6 +1703,7 @@ #ifndef NANO_TINY if (s->scfunc == do_toggle_void) { do_toggle(s->toggle); + if(s->toggle != CUT_TO_END) preserve = TRUE; } else #endif Index: src/nano.h =================================================================== --- src/nano.h (revision 5049) +++ src/nano.h (working copy) @@ -572,7 +572,7 @@ /* Extra bits for the undo function. */ #define UNdel_del (1<<0) #define UNdel_backspace (1<<1) -#define UNcut_marked_backwards (1<<2) +#define UNcut_marked_forward (1<<2) #define UNcut_cutline (1<<3) #endif /* !NANO_TINY */ Index: src/text.c =================================================================== --- src/text.c (revision 5049) +++ src/text.c (working copy) @@ -388,7 +388,7 @@ copy_from_filestruct(u->cutbuffer); - if (u->xflags == UNcut_cutline || u->xflags == UNcut_marked_backwards || u->type == CUT_EOF) + if (u->xflags != UNcut_marked_forward && u->type != PASTE) goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); } @@ -406,11 +406,11 @@ openfile->placewewant = xplustabs(); } - openfile->mark_set = ISSET(CUT_TO_END) ? u->mark_set : TRUE; + openfile->mark_set = TRUE; openfile->mark_begin = fsfromline(u->mark_begin_lineno); openfile->mark_begin_x = (u->xflags == UNcut_cutline) ? 0 : u->mark_begin_x; - do_cut_text(FALSE, u->type == CUT_EOF, TRUE); + do_cut_text(FALSE, FALSE, TRUE); openfile->mark_set = FALSE; openfile->mark_begin = NULL; @@ -1060,16 +1060,22 @@ ssize_t line = u->lineno; u->lineno = u->mark_begin_lineno; u->mark_begin_lineno = line; - u->xflags = UNcut_marked_backwards; - } - } else if (!ISSET(CUT_TO_END)) { + } else + u->xflags = UNcut_marked_forward; + + } else { /* Compute cutbottom for the uncut using our copy. */ u->cutbottom = u->cutbuffer; while (u->cutbottom->next != NULL) u->cutbottom = u->cutbottom->next; - if (u->type != CUT_EOF) - u->lineno++; + + u->lineno = u->mark_begin_lineno + u->cutbottom->lineno - u->cutbuffer->lineno; + if (ISSET(CUT_TO_END) || u->type == CUT_EOF) { + u->begin = strlen(u->cutbottom->data); + if(u->lineno == u->mark_begin_lineno) + u->begin += u->mark_begin_x; } + } break; case REPLACE: case PASTE: