Eliding an unneeded variable and correcting two comments.

And putting the more frequent condition first.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5252 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2015-06-17 10:59:16 +00:00
parent 67667af233
commit 6404101407
2 changed files with 10 additions and 12 deletions

View File

@ -7,6 +7,8 @@
Patch partially by Mark Majeres. The problem was first reported in Patch partially by Mark Majeres. The problem was first reported in
https://lists.gnu.org/archive/html/nano-devel/2015-06/msg00003.html. https://lists.gnu.org/archive/html/nano-devel/2015-06/msg00003.html.
* src/text.c (do_undo): Adjust whitespace after the previous change. * src/text.c (do_undo): Adjust whitespace after the previous change.
* src/text.c (add_undo): Elide an unneeded variable and correct two
comments. And try to put the more frequent condition first.
2015-06-14 Benno Schulenberg <bensberg@justemail.net> 2015-06-14 Benno Schulenberg <bensberg@justemail.net>
* src/winio.c (edit_draw): Add some debugging code to track which * src/winio.c (edit_draw): Add some debugging code to track which

View File

@ -873,17 +873,15 @@ bool execute_command(const char *command)
/* Add a new undo struct to the top of the current pile. */ /* Add a new undo struct to the top of the current pile. */
void add_undo(undo_type current_action) void add_undo(undo_type current_action)
{ {
undo *u;
char *data;
openfilestruct *fs = openfile; openfilestruct *fs = openfile;
/* Last thing we cut to set up the undo for uncut. */ undo *u = fs->current_undo;
/* The thing we did previously. */
/* Ugh, if we were called while cutting not-to-end, non-marked, and /* When doing contiguous adds or contiguous cuts -- which means: with
* on the same lineno, we need to abort here. */ * no cursor movement in between -- don't add a new undo item. */
u = fs->current_undo;
if (u && u->mark_begin_lineno == fs->current->lineno && if (u && u->mark_begin_lineno == fs->current->lineno &&
((current_action == CUT && u->type == CUT && !u->mark_set && keeping_cutbuffer()) || ((current_action == ADD && u->type == ADD && u->mark_begin_x == fs->current_x)) ||
(current_action == ADD && u->type == ADD && u->mark_begin_x == fs->current_x))) (current_action == CUT && u->type == CUT && !u->mark_set && keeping_cutbuffer()))
return; return;
/* When trying to delete the final newline, don't add an undo for it. */ /* When trying to delete the final newline, don't add an undo for it. */
if (current_action == DEL && openfile->current->next == openfile->filebot && if (current_action == DEL && openfile->current->next == openfile->filebot &&
@ -952,8 +950,7 @@ void add_undo(undo_type current_action)
u->lineno = fs->current->next->lineno; u->lineno = fs->current->next->lineno;
u->begin = 0; u->begin = 0;
} }
data = mallocstrcpy(NULL, fs->current->next->data); u->strdata = mallocstrcpy(NULL, fs->current->next->data);
u->strdata = data;
} }
current_action = u->type = JOIN; current_action = u->type = JOIN;
break; break;
@ -967,8 +964,7 @@ void add_undo(undo_type current_action)
case INSERT: case INSERT:
break; break;
case REPLACE: case REPLACE:
data = mallocstrcpy(NULL, fs->current->data); u->strdata = mallocstrcpy(NULL, fs->current->data);
u->strdata = data;
break; break;
case CUT_EOF: case CUT_EOF:
cutbuffer_reset(); cutbuffer_reset();