Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brammool committed Jun 4, 2018
1 parent acb9eff commit adb8fbe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ex_cmds.c
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/testdir/test_edit.vim
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -761,6 +761,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
34,
/**/
33,
/**/
Expand Down

0 comments on commit adb8fbe

Please sign in to comment.