commit f700b422be8a30dbad154894be50472d48ac5ca5
parent 1b2a2e6737c9954ac234140bf85989c3dd99eff8
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 16 Feb 2020 20:11:33 +0100
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.
Diffstat:
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/nano.c b/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)
diff --git a/src/text.c b/src/text.c
@@ -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;