diff --git a/ChangeLog b/ChangeLog index 7eb946aa84064b8021a4998bbbd9ad93e6c85a8a..440a274bcc162d6087ea13077dc7810a4461cdaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-07-02 Mark Majeres <mark@engine12.com> + * src/text.c (undo_cut, redo_cut, update_undo): Handle the + cases of cutting-from-cursor-to-end-of-line properly. + * src/nano.c (do_input): Don't preserve the cutbuffer when + CUT_TO_END is toggled -- it would intermix two cut types. + 2014-07-02 Benno Schulenberg <bensberg@justemail.net> * src/proto.h: Add a typedef for a pointer to a function. * src/global.c (func_from_key): New wrapper. diff --git a/src/nano.c b/src/nano.c index d4460409c662dcb835214877b917554f83bdcd8d..07c87cff8c6982982d0d9b3f2dcff5e417659ce9 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1707,7 +1707,8 @@ int do_input(bool allow_funcs) #ifndef NANO_TINY if (s->scfunc == do_toggle_void) { do_toggle(s->toggle); - preserve = TRUE; + if (s->toggle != CUT_TO_END) + preserve = TRUE; } else #endif { diff --git a/src/nano.h b/src/nano.h index 60fbb9d850c7a0abd76f11ef1ec6ae100e9221ef..f4f43f3babbf0c4435e2d2158dad4bfaf12b0a19 100644 --- a/src/nano.h +++ b/src/nano.h @@ -572,7 +572,7 @@ enum /* 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 */ diff --git a/src/text.c b/src/text.c index 206c7b4576852b7eea3d8d86b190f037ea1c9755..8cb4de3654d8c04b116fbaca51186e61f8623f92 100644 --- a/src/text.c +++ b/src/text.c @@ -388,7 +388,7 @@ void undo_cut(undo *u) 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 @@ void redo_cut(undo *u) 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,15 +1060,19 @@ void update_undo(undo_type action) 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: