Index: src/cut.c =================================================================== --- src/cut.c (revision 5035) +++ src/cut.c (working copy) @@ -88,16 +88,21 @@ void cut_to_eol(void) { size_t data_len = strlen(openfile->current->data); + /* set the mark_begin variables for undo/redo */ + openfile->mark_begin_x = data_len; + openfile->mark_begin = openfile->current; assert(openfile->current_x <= data_len); - if (openfile->current_x < data_len) + if (openfile->current_x < data_len){ /* If we're not at the end of the line, move all the text from * the current position up to it, not counting the newline at * the end, into the cutbuffer. */ move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, openfile->current_x, openfile->current, data_len); - else if (openfile->current != openfile->filebot) { + + openfile->mark_begin = openfile->current; + } else if (openfile->current != openfile->filebot) { /* If we're at the end of the line, and it isn't the last line * of the file, move all the text from the current position up * to the beginning of the next line, i.e. the newline at the @@ -105,6 +110,9 @@ move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, openfile->current_x, openfile->current->next, 0); openfile->placewewant = xplustabs(); + + openfile->mark_begin = openfile->current->next; + openfile->mark_begin_x = 0; } } Index: src/nano.c =================================================================== --- src/nano.c (revision 5035) +++ src/nano.c (working copy) @@ -1704,6 +1704,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 5035) +++ src/nano.h (working copy) @@ -568,7 +568,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 5035) +++ 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,7 +406,7 @@ 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; @@ -1060,9 +1060,10 @@ 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) @@ -1070,6 +1071,12 @@ if (u->type != CUT_EOF) u->lineno++; } + + if (ISSET(CUT_TO_END)) { + /* these values were set in cut_to_eol */ + u->lineno = openfile->mark_begin->lineno; + u->begin = openfile->mark_begin_x; + } break; case REPLACE: case PASTE: