From 83b89a49ef60e20a26a4d96a7606758de9192ed1 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 7 Jun 2016 11:52:57 +0200 Subject: [PATCH] text: remove a redundant undo element Implement its single use case by making better use of another element. --- src/nano.h | 13 +++++++------ src/text.c | 9 ++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/nano.h b/src/nano.h index 7ef66d55..0079a6d1 100644 --- a/src/nano.h +++ b/src/nano.h @@ -357,13 +357,12 @@ typedef struct undo { /* Copy of the cutbuffer. */ filestruct *cutbottom; /* Copy of cutbottom. */ - bool mark_set; - /* Was the marker set when we cut? */ ssize_t mark_begin_lineno; - /* copy copy copy */ + /* Mostly the line number of the current line; sometimes something else. */ size_t mark_begin_x; - /* Another shadow variable. */ + /* The x position corresponding to the above line number. */ struct undo *next; + /* A pointer to the undo item of the preceding action. */ } undo; #endif /* !NANO_TINY */ @@ -574,8 +573,10 @@ enum /* Some extra flags for the undo function. */ #define WAS_FINAL_BACKSPACE (1<<1) -#define WAS_MARKED_FORWARD (1<<2) -#define WAS_WHOLE_LINE (1<<3) +#define WAS_WHOLE_LINE (1<<2) +/* The flags for the mark need to be the highest. */ +#define MARK_WAS_SET (1<<3) +#define WAS_MARKED_FORWARD (1<<4) #endif /* !NANO_TINY */ /* The maximum number of entries displayed in the main shortcut list. */ diff --git a/src/text.c b/src/text.c index a2968509..d45109c5 100644 --- a/src/text.c +++ b/src/text.c @@ -1156,7 +1156,7 @@ void add_undo(undo_type action) * no cursor movement in between -- don't add a new undo item. */ if (u && u->mark_begin_lineno == openfile->current->lineno && action == openfile->last_action && ((action == ADD && u->type == ADD && u->mark_begin_x == openfile->current_x) || - (action == CUT && u->type == CUT && !u->mark_set && keeping_cutbuffer()))) + (action == CUT && u->type == CUT && u->xflags < MARK_WAS_SET && keeping_cutbuffer()))) return; /* Blow away newer undo items if we add somewhere in the middle. */ @@ -1190,7 +1190,6 @@ void add_undo(undo_type action) u->begin = openfile->current_x; u->mark_begin_lineno = openfile->current->lineno; u->mark_begin_x = openfile->current_x; - u->mark_set = FALSE; u->wassize = openfile->totsize; u->xflags = 0; u->grouping = NULL; @@ -1244,10 +1243,10 @@ void add_undo(undo_type action) break; case CUT: cutbuffer_reset(); - u->mark_set = openfile->mark_set; - if (u->mark_set) { + if (openfile->mark_set) { u->mark_begin_lineno = openfile->mark_begin->lineno; u->mark_begin_x = openfile->mark_begin_x; + u->xflags = MARK_WAS_SET; } else if (!ISSET(CUT_TO_END)) { /* The entire line is being cut regardless of the cursor position. */ u->begin = 0; @@ -1379,7 +1378,7 @@ fprintf(stderr, " >> Updating... action = %d, openfile->last_action = %d, openf break; free_filestruct(u->cutbuffer); u->cutbuffer = copy_filestruct(cutbuffer); - if (u->mark_set) { + if (u->xflags == MARK_WAS_SET) { /* If the "marking" operation was from right-->left or * bottom-->top, then swap the mark points. */ if ((u->lineno == u->mark_begin_lineno && u->begin < u->mark_begin_x)