text: remove a redundant undo element

Implement its single use case by making better use of another element.
master
Benno Schulenberg 2016-06-07 11:52:57 +02:00
parent 87a254400e
commit 83b89a49ef
2 changed files with 11 additions and 11 deletions

View File

@ -357,13 +357,12 @@ typedef struct undo {
/* Copy of the cutbuffer. */ /* Copy of the cutbuffer. */
filestruct *cutbottom; filestruct *cutbottom;
/* Copy of cutbottom. */ /* Copy of cutbottom. */
bool mark_set;
/* Was the marker set when we cut? */
ssize_t mark_begin_lineno; ssize_t mark_begin_lineno;
/* copy copy copy */ /* Mostly the line number of the current line; sometimes something else. */
size_t mark_begin_x; size_t mark_begin_x;
/* Another shadow variable. */ /* The x position corresponding to the above line number. */
struct undo *next; struct undo *next;
/* A pointer to the undo item of the preceding action. */
} undo; } undo;
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
@ -574,8 +573,10 @@ enum
/* Some extra flags for the undo function. */ /* Some extra flags for the undo function. */
#define WAS_FINAL_BACKSPACE (1<<1) #define WAS_FINAL_BACKSPACE (1<<1)
#define WAS_MARKED_FORWARD (1<<2) #define WAS_WHOLE_LINE (1<<2)
#define WAS_WHOLE_LINE (1<<3) /* 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 */ #endif /* !NANO_TINY */
/* The maximum number of entries displayed in the main shortcut list. */ /* The maximum number of entries displayed in the main shortcut list. */

View File

@ -1156,7 +1156,7 @@ void add_undo(undo_type action)
* no cursor movement in between -- don't add a new undo item. */ * 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 && 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 == 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; return;
/* Blow away newer undo items if we add somewhere in the middle. */ /* 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->begin = openfile->current_x;
u->mark_begin_lineno = openfile->current->lineno; u->mark_begin_lineno = openfile->current->lineno;
u->mark_begin_x = openfile->current_x; u->mark_begin_x = openfile->current_x;
u->mark_set = FALSE;
u->wassize = openfile->totsize; u->wassize = openfile->totsize;
u->xflags = 0; u->xflags = 0;
u->grouping = NULL; u->grouping = NULL;
@ -1244,10 +1243,10 @@ void add_undo(undo_type action)
break; break;
case CUT: case CUT:
cutbuffer_reset(); cutbuffer_reset();
u->mark_set = openfile->mark_set; if (openfile->mark_set) {
if (u->mark_set) {
u->mark_begin_lineno = openfile->mark_begin->lineno; u->mark_begin_lineno = openfile->mark_begin->lineno;
u->mark_begin_x = openfile->mark_begin_x; u->mark_begin_x = openfile->mark_begin_x;
u->xflags = MARK_WAS_SET;
} else if (!ISSET(CUT_TO_END)) { } else if (!ISSET(CUT_TO_END)) {
/* The entire line is being cut regardless of the cursor position. */ /* The entire line is being cut regardless of the cursor position. */
u->begin = 0; u->begin = 0;
@ -1379,7 +1378,7 @@ fprintf(stderr, " >> Updating... action = %d, openfile->last_action = %d, openf
break; break;
free_filestruct(u->cutbuffer); free_filestruct(u->cutbuffer);
u->cutbuffer = copy_filestruct(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 /* If the "marking" operation was from right-->left or
* bottom-->top, then swap the mark points. */ * bottom-->top, then swap the mark points. */
if ((u->lineno == u->mark_begin_lineno && u->begin < u->mark_begin_x) if ((u->lineno == u->mark_begin_lineno && u->begin < u->mark_begin_x)