From 8d0b7a490d8accdca82afdcbce596fc54495915e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 26 Sep 2018 16:42:23 +0200 Subject: [PATCH] undo: move another piece of checking to the two places that need it And in the bargain get rid of a function that is used just once. --- src/cut.c | 13 ++++++------- src/nano.c | 7 ++++++- src/proto.h | 1 - src/text.c | 8 -------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/cut.c b/src/cut.c index 7cd2579d..69c50062 100644 --- a/src/cut.c +++ b/src/cut.c @@ -33,12 +33,6 @@ void cutbuffer_reset(void) keep_cutbuffer = FALSE; } -/* Return the status of cutbuffer preservation. */ -inline bool keeping_cutbuffer(void) -{ - return keep_cutbuffer; -} - /* If we aren't on the last line of the file, move all the text of the * current line, plus the newline at the end, into the cutbuffer. If we * are, move all of the text of the current line into the cutbuffer. In @@ -193,7 +187,12 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof) void do_cut_text_void(void) { #ifndef NANO_TINY - add_undo(CUT); + /* Only add a new undo item when the current item is not a CUT or when + * the current cut is not contiguous with the previous cutting. */ + if (openfile->last_action != CUT || openfile->current_undo == NULL || + openfile->current_undo->mark_begin_lineno != openfile->current->lineno || + !keep_cutbuffer) + add_undo(CUT); do_cut_text(FALSE, openfile->mark, FALSE); update_undo(CUT); #else diff --git a/src/nano.c b/src/nano.c index d4939ade..d5f195e1 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1885,7 +1885,12 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) set_modified(); #ifndef NANO_TINY - add_undo(ADD); + /* Only add a new undo item when the current item is not an ADD or when + * the current typing is not contiguous with the previous typing. */ + if (openfile->last_action != ADD || openfile->current_undo == NULL || + openfile->current_undo->mark_begin_lineno != openfile->current->lineno || + openfile->current_undo->mark_begin_x != openfile->current_x) + add_undo(ADD); /* Note that current_x has not yet been incremented. */ if (openfile->current == openfile->mark && diff --git a/src/proto.h b/src/proto.h index 71ef8eab..0b93ed64 100644 --- a/src/proto.h +++ b/src/proto.h @@ -251,7 +251,6 @@ void precalc_multicolorinfo(void); /* Most functions in cut.c. */ void cutbuffer_reset(void); -bool keeping_cutbuffer(void); #ifndef NANO_TINY void cut_marked(bool *right_side_up); #endif diff --git a/src/text.c b/src/text.c index 9c5d0b8b..d201902d 100644 --- a/src/text.c +++ b/src/text.c @@ -1319,14 +1319,6 @@ void add_undo(undo_type action) undo *u = openfile->current_undo; /* The thing we did previously. */ - /* When doing contiguous adds or cuts, don't add a new undo item, but - * let a later update call update the existing item. */ - if (u != NULL && action == openfile->last_action && action == u->type && - openfile->current->lineno == u->mark_begin_lineno && - ((action == ADD && u->mark_begin_x == openfile->current_x) || - (action == CUT && keeping_cutbuffer()))) - return; - /* Blow away newer undo items if we add somewhere in the middle. */ discard_until(u, openfile, TRUE);