commit b9638cb7ccf9df9a8a0f0b1b5c9f52839c557c12
parent d646a3b97b7d2fddcc1c98a59db0c753edf5e4c8
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Mon, 27 Nov 2017 11:11:30 -0600
undo: when adding text adds a magicline, an undo should remove both
This fixes http://savannah.gnu.org/bugs/?52523.
Diffstat:
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -1813,13 +1813,6 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
if (!allow_cntrls && is_ascii_cntrl_char(*(output + i - char_len)))
continue;
- /* If we're adding to the magicline, create a new magicline. */
- if (!ISSET(NO_NEWLINES) && openfile->filebot == openfile->current) {
- new_magicline();
- if (margin > 0)
- refresh_needed = TRUE;
- }
-
/* Make room for the new character and copy it into the line. */
openfile->current->data = charealloc(openfile->current->data,
current_len + char_len + 1);
@@ -1856,6 +1849,13 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
update_undo(ADD);
#endif
+ /* If we've added text to the magicline, create a new magicline. */
+ if (openfile->filebot == openfile->current && !ISSET(NO_NEWLINES)) {
+ new_magicline();
+ if (margin > 0)
+ refresh_needed = TRUE;
+ }
+
#ifdef ENABLE_WRAPPING
/* If text gets wrapped, the edit window needs a refresh. */
if (!ISSET(NO_WRAP) && do_wrap(openfile->current))
diff --git a/src/nano.h b/src/nano.h
@@ -607,9 +607,10 @@ enum
/* Some extra flags for the undo function. */
#define WAS_FINAL_BACKSPACE (1<<1)
#define WAS_WHOLE_LINE (1<<2)
+#define WAS_FINAL_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)
+#define MARK_WAS_SET (1<<4)
+#define WAS_MARKED_FORWARD (1<<5)
#endif /* !NANO_TINY */
/* The maximum number of entries displayed in the main shortcut list. */
diff --git a/src/text.c b/src/text.c
@@ -734,6 +734,8 @@ void do_undo(void)
/* TRANSLATORS: The next twelve strings describe actions
* that are undone or redone. It are all nouns, not verbs. */
undidmsg = _("text add");
+ if (u->xflags == WAS_FINAL_LINE && !ISSET(NO_NEWLINES))
+ remove_magicline();
data = charalloc(strlen(f->data) - strlen(u->strdata) + 1);
strncpy(data, f->data, u->begin);
strcpy(&data[u->begin], &f->data[u->begin + strlen(u->strdata)]);
@@ -907,6 +909,8 @@ void do_redo(void)
switch (u->type) {
case ADD:
redidmsg = _("text add");
+ if (u->xflags == WAS_FINAL_LINE && !ISSET(NO_NEWLINES))
+ new_magicline();
data = charalloc(strlen(f->data) + strlen(u->strdata) + 1);
strncpy(data, f->data, u->begin);
strcpy(&data[u->begin], u->strdata);
@@ -1272,6 +1276,9 @@ void add_undo(undo_type action)
/* We need to start copying data into the undo buffer
* or we won't be able to restore it later. */
case ADD:
+ /* If a new magic line will be added, an undo should remove it. */
+ if (openfile->current == openfile->filebot && openfile->current_x == 0)
+ u->xflags = WAS_FINAL_LINE;
u->wassize--;
break;
case BACK: