bw!
endfunc
+func Test_restore_cursor_position_after_undo()
+ CheckFeature persistent_undo
+ sp samples/test_undo.txt
+
+ 3 | exe "norm! gqk" | undojoin | 1 delete
+ call assert_equal(1, line('.'))
+ norm! u
+ call assert_equal(3, line('.'))
+ bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
// Decide about the cursor position, depending on what text changed.
// Don't set it yet, it may be invalid if lines are going to be added.
- if (top < newlnum)
{
// If the saved cursor is somewhere in this undo block, move it to
// the remembered position. Makes "gwap" put the cursor back
if (lnum >= top && lnum <= top + newsize + 1)
{
new_curpos = curhead->uh_cursor;
- newlnum = new_curpos.lnum - 1;
+
+ // We don't want other entries to override saved cursor
+ // position.
+ newlnum = -1;
}
- else
+ else if (top < newlnum)
{
// Use the first line that actually changed. Avoids that
// undoing auto-formatting puts the cursor in the previous