diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-04-25 22:22:01 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-04-25 22:22:01 +0200 |
commit | a68e59590905da9b4448ff1fcac929ad1a18da9e (patch) | |
tree | 34c79c9572424b3daf7d6be1d968d675c674cf10 /src/testdir/test_autocmd.vim | |
parent | a561a41a70db7a9367f883c1dbb14e69b3364d08 (diff) |
patch 8.1.1205: a BufReadPre autocommand may cause the cursor to movev8.1.1205
Problem: A BufReadPre autocommand may cause the cursor to move.
Solution: Restore the cursor position after executing the autocommand,
unless the autocommand moved it. (Christian Brabandt,
closes #4302, closes #4294)
Diffstat (limited to 'src/testdir/test_autocmd.vim')
-rw-r--r-- | src/testdir/test_autocmd.vim | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index 8db06d0831..55d725e48a 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -1485,6 +1485,51 @@ func Test_autocmd_once() call assert_fails('au WinNew * ++once ++once echo bad', 'E983:') endfunc +func Test_autocmd_bufreadpre() + new + let b:bufreadpre = 1 + call append(0, range(100)) + w! XAutocmdBufReadPre.txt + autocmd BufReadPre <buffer> :let b:bufreadpre += 1 + norm! 50gg + sp + norm! 100gg + wincmd p + let g:wsv1 = winsaveview() + wincmd p + let g:wsv2 = winsaveview() + " triggers BufReadPre, should not move the cursor in either window + " The topline may change one line in a large window. + edit + call assert_inrange(g:wsv2.topline - 1, g:wsv2.topline + 1, winsaveview().topline) + call assert_equal(g:wsv2.lnum, winsaveview().lnum) + call assert_equal(2, b:bufreadpre) + wincmd p + call assert_equal(g:wsv1.topline, winsaveview().topline) + call assert_equal(g:wsv1.lnum, winsaveview().lnum) + call assert_equal(2, b:bufreadpre) + " Now set the cursor position in an BufReadPre autocommand + " (even though the position will be invalid, this should make Vim reset the + " cursor position in the other window. + wincmd p + set cpo+=g + " won't do anything, but try to set the cursor on an invalid lnum + autocmd BufReadPre <buffer> :norm! 70gg + " triggers BufReadPre, should not move the cursor in either window + e + call assert_equal(1, winsaveview().topline) + call assert_equal(1, winsaveview().lnum) + call assert_equal(3, b:bufreadpre) + wincmd p + call assert_equal(g:wsv1.topline, winsaveview().topline) + call assert_equal(g:wsv1.lnum, winsaveview().lnum) + call assert_equal(3, b:bufreadpre) + close + close + call delete('XAutocmdBufReadPre.txt') + set cpo-=g +endfunc + " FileChangedShell tested in test_filechanged.vim " Tests for the following autocommands: |