From 03747085972ce9e95cf26e9d84dcdd1ddb0333a7 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 11 Oct 2019 15:29:15 +0200 Subject: [PATCH] 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. --- src/text.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/text.c b/src/text.c index 7921eac7..dbf45c4e 100644 --- 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;