nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit a52ac1375af35c5cf9eed154ed21b4bd9d8aaebf
parent 4990713e9e8d9233b94ac92856df482601830842
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 21 Apr 2022 12:23:17 +0200

formatting: change cursor position only after saving it in the undo item

When one wants an Undo to restore the cursor to where it was before an
operation, one shouldn't fiddle with the position before it is stored
in the relevant undo item.

This fixes https://savannah.gnu.org/bugs/?62341.

Bug existed since version 4.9, commit 38af812a.

(This effectively reverts commit 38af812a from two years ago.)

Diffstat:
Msrc/text.c | 17++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -2050,11 +2050,19 @@ bool replace_buffer(const char *filename, undo_type action, const char *operatio if (descriptor < 0) return FALSE; - cutbuffer = NULL; - #ifndef NANO_TINY add_undo(COUPLE_BEGIN, operation); +#endif + + /* When nothing is marked, start at the top of the buffer. */ + if (!openfile->mark) { + openfile->current = openfile->filetop; + openfile->current_x = 0; + } + cutbuffer = NULL; + +#ifndef NANO_TINY /* Cut either the marked region or the whole buffer. */ add_undo(action, NULL); do_snip(openfile->mark != NULL, openfile->mark == NULL, FALSE); @@ -2174,14 +2182,9 @@ void treat(char *tempfile_name, char *theprogram, bool spelling) openfile->mark = line_from_number(was_mark_lineno); } else #endif - { - openfile->current = openfile->filetop; - openfile->current_x = 0; - replaced = replace_buffer(tempfile_name, CUT_TO_EOF, /* TRANSLATORS: The next two go with Undid/Redid messages. */ (spelling ? N_("spelling correction") : N_("formatting"))); - } /* Go back to the old position. */ goto_line_posx(was_lineno, was_x);