summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-02-04 10:58:34 +0000
committerBram Moolenaar <Bram@vim.org>2023-02-04 10:58:34 +0000
commit49f0524fb575bb1cf4881e472afab7d37c579440 (patch)
treef00b08a90af6e3c63cd3683d999e7f3b00c1223c /src
parent4be18e77ff2d9a85d01e9d62335542755b26d5d5 (diff)
patch 9.0.1277: cursor may move with autocmd in Visual modev9.0.1277
Problem: Cursor may move with autocmd in Visual mode. Solution: Restore "VIsual_active" before calling check_cursor(). (closes #11939)
Diffstat (limited to 'src')
-rw-r--r--src/autocmd.c5
-rw-r--r--src/testdir/test_functions.vim11
-rw-r--r--src/version.c2
3 files changed, 16 insertions, 2 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index c18d2a15ab..a409379b61 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -1695,6 +1695,7 @@ win_found:
globaldir = aco->globaldir;
// the buffer contents may have changed
+ VIsual_active = aco->save_VIsual_active;
check_cursor();
if (curwin->w_topline > curbuf->b_ml.ml_line_count)
{
@@ -1741,14 +1742,16 @@ win_found:
curwin = save_curwin;
curbuf = curwin->w_buffer;
prevwin = win_find_by_id(aco->save_prevwin_id);
+
// In case the autocommand moves the cursor to a position that
// does not exist in curbuf.
+ VIsual_active = aco->save_VIsual_active;
check_cursor();
}
}
- check_cursor(); // just in case lines got deleted
VIsual_active = aco->save_VIsual_active;
+ check_cursor(); // just in case lines got deleted
if (VIsual_active)
check_pos(curbuf, &VIsual);
}
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 99403e295a..3bea88df17 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -1648,7 +1648,7 @@ endfunc
func Test_setbufvar_options()
" This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the
- " window layout.
+ " window layout and cursor position.
call assert_equal(1, winnr('$'))
split dummy_preview
resize 2
@@ -1662,11 +1662,20 @@ func Test_setbufvar_options()
execute 'belowright vertical split #' . dummy_buf
call assert_equal(wh, winheight(0))
let dum1_id = win_getid()
+ call setline(1, 'foo')
+ normal! V$
+ call assert_equal(4, col('.'))
+ call setbufvar('dummy_preview', '&buftype', 'nofile')
+ call assert_equal(4, col('.'))
wincmd h
let wh = winheight(0)
+ call setline(1, 'foo')
+ normal! V$
+ call assert_equal(4, col('.'))
let dummy_buf = bufnr('dummy_buf2', v:true)
eval 'nofile'->setbufvar(dummy_buf, '&buftype')
+ call assert_equal(4, col('.'))
execute 'belowright vertical split #' . dummy_buf
call assert_equal(wh, winheight(0))
diff --git a/src/version.c b/src/version.c
index 5bf3348d29..0768881b99 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1277,
+/**/
1276,
/**/
1275,