# HG changeset patch # User Christian Brabandt # Date 1528137906 -7200 # Node ID bcda3b864c3121b2ff0a35122756908a630628f1 # Parent bdbabef0d4eadcefe035276ca896c677e54a1b59 patch 8.1.0034: cursor not restored with ":edit #" commit https://github.com/vim/vim/commit/adb8fbec4f4059d214fe6acf2485ffd35e803450 Author: Bram Moolenaar Date: Mon Jun 4 20:34:23 2018 +0200 patch 8.1.0034: cursor not restored with ":edit #" Problem: Cursor not restored with ":edit #". Solution: Don't assume autocommands moved the cursor when it was moved to the first non-blank. diff --git a/src/ex_cmds.c b/src/ex_cmds.c --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -4193,11 +4193,18 @@ do_ecmd( check_arg_idx(curwin); /* If autocommands change the cursor position or topline, we should - * keep it. Also when it moves within a line. */ + * keep it. Also when it moves within a line. But not when it moves + * to the first non-blank. */ if (!EQUAL_POS(curwin->w_cursor, orig_pos)) { - newlnum = curwin->w_cursor.lnum; - newcol = curwin->w_cursor.col; + char_u *text = ml_get_curline(); + + if (curwin->w_cursor.lnum != orig_pos.lnum + || curwin->w_cursor.col != (int)(skipwhite(text) - text)) + { + newlnum = curwin->w_cursor.lnum; + newcol = curwin->w_cursor.col; + } } if (curwin->w_topline == topline) topline = 0; diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim --- a/src/testdir/test_edit.vim +++ b/src/testdir/test_edit.vim @@ -1387,3 +1387,17 @@ func Test_edit_quit() only endfunc +func Test_edit_alt() + " Keeping the cursor line didn't happen when the first line has indent. + new + call setline(1, [' one', 'two', 'three']) + w XAltFile + $ + call assert_equal(3, line('.')) + e Xother + e # + call assert_equal(3, line('.')) + + bwipe XAltFile + call delete('XAltFile') +endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 34, +/**/ 33, /**/ 32,