From 92213f9de8952a9d58d27ba03229ba619afd8999 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 2 Jul 2014 20:29:57 +0000 Subject: [PATCH] Handling the cases of cutting-from-cursor-to-end-of-line (that is, when CUT_TO_END is set) properly. Patch by Mark Majeres. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5054 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++++ src/nano.c | 3 ++- src/nano.h | 2 +- src/text.c | 20 ++++++++++++-------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7eb946aa..440a274b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-07-02 Mark Majeres + * 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 * 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 d4460409..07c87cff 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 60fbb9d8..f4f43f3b 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 206c7b45..8cb4de36 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: -- 2.39.5