tweaks: call add_undo() before the character is actually added
And before the buffer size is adjusted, so that the add_undo() doesn't need to correct the stored former size of the buffer. This will allow the injection of multiple characters at once, in the next commit.master
parent
1b2a2e6737
commit
f700b422be
16
src/nano.c
16
src/nano.c
|
@ -1656,6 +1656,15 @@ void inject(char *burst, size_t count)
|
|||
if (burst[index] == '\0')
|
||||
burst[index] = '\n';
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* 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->mark_begin_lineno != openfile->current->lineno ||
|
||||
openfile->current_undo->mark_begin_x != openfile->current_x)
|
||||
add_undo(ADD, NULL);
|
||||
#endif
|
||||
|
||||
charlen = char_length(burst + index);
|
||||
|
||||
/* Make room for the new character and copy it into the line. */
|
||||
|
@ -1674,13 +1683,6 @@ void inject(char *burst, size_t count)
|
|||
set_modified();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* 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->mark_begin_lineno != openfile->current->lineno ||
|
||||
openfile->current_undo->mark_begin_x != openfile->current_x)
|
||||
add_undo(ADD, NULL);
|
||||
|
||||
/* Note that current_x has not yet been incremented. */
|
||||
if (openfile->current == openfile->mark &&
|
||||
openfile->current_x < openfile->mark_x)
|
||||
|
|
|
@ -1159,7 +1159,6 @@ void add_undo(undo_type action, const char *message)
|
|||
/* If a new magic line will be added, an undo should remove it. */
|
||||
if (openfile->current == openfile->filebot)
|
||||
u->xflags |= WAS_FINAL_LINE;
|
||||
u->wassize--;
|
||||
break;
|
||||
case ENTER:
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue