nano

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

commit 03747085972ce9e95cf26e9d84dcdd1ddb0333a7
parent 101987f5c6d72135449c5f6a7780e57a820c4973
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 11 Oct 2019 15:29:15 +0200

undo: put the cursor back on the original row for a full-buffer operation

When an operation that replaces the entire buffer is undone, the
position of the viewport is lost.  Compensate for this by storing
the row of the cursor in the undo item, and, after executing the
undo item, arranging the viewport so that the cursor is back on
the original row -- the row where the operation was invoked.

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

Diffstat:
Msrc/text.c | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -642,6 +642,8 @@ void do_undo(void) case COUPLE_BEGIN: undidmsg = u->strdata; goto_line_posx(u->lineno, u->begin); + openfile->current_y = u->mark_begin_lineno; + adjust_viewport(STATIONARY); break; case COUPLE_END: openfile->current_undo = openfile->current_undo->next; @@ -806,6 +808,7 @@ void do_redo(void) case COUPLE_END: redidmsg = u->strdata; goto_line_posx(u->lineno, u->begin); + adjust_viewport(STATIONARY); break; case INDENT: handle_indent_action(u, FALSE, TRUE); @@ -1224,6 +1227,7 @@ void add_undo(undo_type action, const char *message) break; case INSERT: case COUPLE_BEGIN: + u->mark_begin_lineno = openfile->current_y; case COUPLE_END: u->strdata = mallocstrcpy(NULL, _(message)); break;