tweaks: add a supporting variable, in order to condense some statements
parent
ac61254581
commit
e39e2ddf52
32
src/text.c
32
src/text.c
|
@ -1095,14 +1095,15 @@ void discard_until(const undostruct *thisitem, openfilestruct *thefile, bool kee
|
||||||
void add_undo(undo_type action, const char *message)
|
void add_undo(undo_type action, const char *message)
|
||||||
{
|
{
|
||||||
undostruct *u = nmalloc(sizeof(undostruct));
|
undostruct *u = nmalloc(sizeof(undostruct));
|
||||||
|
linestruct *thisline = openfile->current;
|
||||||
|
|
||||||
/* Initialize the newly allocated undo item. */
|
/* Initialize the newly allocated undo item. */
|
||||||
u->type = action;
|
u->type = action;
|
||||||
u->strdata = NULL;
|
u->strdata = NULL;
|
||||||
u->cutbuffer = NULL;
|
u->cutbuffer = NULL;
|
||||||
u->head_lineno = openfile->current->lineno;
|
u->head_lineno = thisline->lineno;
|
||||||
u->head_x = openfile->current_x;
|
u->head_x = openfile->current_x;
|
||||||
u->tail_lineno = openfile->current->lineno;
|
u->tail_lineno = thisline->lineno;
|
||||||
u->tail_x = openfile->current_x;
|
u->tail_x = openfile->current_x;
|
||||||
u->wassize = openfile->totsize;
|
u->wassize = openfile->totsize;
|
||||||
u->newsize = openfile->totsize;
|
u->newsize = openfile->totsize;
|
||||||
|
@ -1133,7 +1134,7 @@ void add_undo(undo_type action, const char *message)
|
||||||
switch (u->type) {
|
switch (u->type) {
|
||||||
case ADD:
|
case ADD:
|
||||||
/* If a new magic line will be added, an undo should remove it. */
|
/* If a new magic line will be added, an undo should remove it. */
|
||||||
if (openfile->current == openfile->filebot)
|
if (thisline == openfile->filebot)
|
||||||
u->xflags |= INCLUDED_LAST_LINE;
|
u->xflags |= INCLUDED_LAST_LINE;
|
||||||
break;
|
break;
|
||||||
case ENTER:
|
case ENTER:
|
||||||
|
@ -1141,34 +1142,32 @@ void add_undo(undo_type action, const char *message)
|
||||||
case BACK:
|
case BACK:
|
||||||
/* If the next line is the magic line, don't ever undo this
|
/* If the next line is the magic line, don't ever undo this
|
||||||
* backspace, as it won't actually have deleted anything. */
|
* backspace, as it won't actually have deleted anything. */
|
||||||
if (openfile->current->next == openfile->filebot &&
|
if (thisline->next == openfile->filebot && thisline->data[0] != '\0')
|
||||||
openfile->current->data[0] != '\0')
|
|
||||||
u->xflags |= WAS_BACKSPACE_AT_EOF;
|
u->xflags |= WAS_BACKSPACE_AT_EOF;
|
||||||
/* Fall-through. */
|
/* Fall-through. */
|
||||||
case DEL:
|
case DEL:
|
||||||
/* When not at the end of a line, store the deleted character;
|
/* When not at the end of a line, store the deleted character;
|
||||||
* otherwise, morph the undo item into a line join. */
|
* otherwise, morph the undo item into a line join. */
|
||||||
if (openfile->current->data[openfile->current_x] != '\0') {
|
if (thisline->data[openfile->current_x] != '\0') {
|
||||||
int charlen = char_length(openfile->current->data + u->head_x);
|
int charlen = char_length(thisline->data + u->head_x);
|
||||||
|
|
||||||
u->strdata = measured_copy(openfile->current->data + u->head_x,
|
u->strdata = measured_copy(thisline->data + u->head_x, charlen);
|
||||||
charlen);
|
|
||||||
if (u->type == BACK)
|
if (u->type == BACK)
|
||||||
u->tail_x += charlen;
|
u->tail_x += charlen;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
action = JOIN;
|
action = JOIN;
|
||||||
if (openfile->current->next != NULL) {
|
if (thisline->next != NULL) {
|
||||||
if (u->type == BACK) {
|
if (u->type == BACK) {
|
||||||
u->head_lineno = openfile->current->next->lineno;
|
u->head_lineno = thisline->next->lineno;
|
||||||
u->head_x = 0;
|
u->head_x = 0;
|
||||||
}
|
}
|
||||||
u->strdata = copy_of(openfile->current->next->data);
|
u->strdata = copy_of(thisline->next->data);
|
||||||
}
|
}
|
||||||
u->type = JOIN;
|
u->type = JOIN;
|
||||||
break;
|
break;
|
||||||
case REPLACE:
|
case REPLACE:
|
||||||
u->strdata = copy_of(openfile->current->data);
|
u->strdata = copy_of(thisline->data);
|
||||||
break;
|
break;
|
||||||
#ifdef ENABLE_WRAPPING
|
#ifdef ENABLE_WRAPPING
|
||||||
case SPLIT_BEGIN:
|
case SPLIT_BEGIN:
|
||||||
|
@ -1192,8 +1191,7 @@ void add_undo(undo_type action, const char *message)
|
||||||
u->tail_lineno = openfile->mark->lineno;
|
u->tail_lineno = openfile->mark->lineno;
|
||||||
u->tail_x = openfile->mark_x;
|
u->tail_x = openfile->mark_x;
|
||||||
}
|
}
|
||||||
if (openfile->current == openfile->filebot ||
|
if (u->tail_lineno == openfile->filebot->lineno)
|
||||||
openfile->mark == openfile->filebot)
|
|
||||||
u->xflags |= INCLUDED_LAST_LINE;
|
u->xflags |= INCLUDED_LAST_LINE;
|
||||||
} else if (!ISSET(CUT_FROM_CURSOR)) {
|
} else if (!ISSET(CUT_FROM_CURSOR)) {
|
||||||
/* The entire line is being cut regardless of the cursor position. */
|
/* The entire line is being cut regardless of the cursor position. */
|
||||||
|
@ -1204,11 +1202,11 @@ void add_undo(undo_type action, const char *message)
|
||||||
case PASTE:
|
case PASTE:
|
||||||
u->cutbuffer = copy_buffer(cutbuffer);
|
u->cutbuffer = copy_buffer(cutbuffer);
|
||||||
u->tail_lineno += cutbottom->lineno - cutbuffer->lineno;
|
u->tail_lineno += cutbottom->lineno - cutbuffer->lineno;
|
||||||
if (openfile->current == openfile->filebot)
|
if (thisline == openfile->filebot)
|
||||||
u->xflags |= INCLUDED_LAST_LINE;
|
u->xflags |= INCLUDED_LAST_LINE;
|
||||||
break;
|
break;
|
||||||
case INSERT:
|
case INSERT:
|
||||||
if (openfile->current == openfile->filebot)
|
if (thisline == openfile->filebot)
|
||||||
u->xflags |= INCLUDED_LAST_LINE;
|
u->xflags |= INCLUDED_LAST_LINE;
|
||||||
break;
|
break;
|
||||||
case COUPLE_BEGIN:
|
case COUPLE_BEGIN:
|
||||||
|
|
Loading…
Reference in New Issue