diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2019-05-08 18:01:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-08 18:01:21 +0200 |
| commit | 8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1 (patch) | |
| tree | e22baa51856201ff97e2167a82a37a625ab6d20d /src/nvim/testdir | |
| parent | d36ef9339f398988d4ccefd4780b2f289b0c7f83 (diff) | |
| download | rneovim-8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1.tar.gz rneovim-8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1.tar.bz2 rneovim-8330cc22afec67d9dbc2ad8b4a39eaf62fdf16d1.zip | |
vim-patch:8.1.1205: BufReadPre may move the cursor #9980
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 vim/vim#4302, closes vim/vim#4294)
https://github.com/vim/vim/commit/a68e59590905da9b4448ff1fcac929ad1a18da9e
Diffstat (limited to 'src/nvim/testdir')
| -rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index d13761e2ba..1c1da0572b 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1425,6 +1425,50 @@ 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 + 1 + " 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') +endfunc + " Tests for the following autocommands: " - FileWritePre writing a compressed file " - FileReadPost reading a compressed file |