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.
master
Benno Schulenberg 2019-10-11 15:29:15 +02:00
parent 101987f5c6
commit 0374708597
1 changed files with 4 additions and 0 deletions

View File

@ -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;