summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-08-13 14:09:44 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-13 14:09:44 +0100
commitcfeb8a584be11758cf71ae02f6c937b06d6bb66f (patch)
tree9f024147fdbebdf5d78a9860ec6bb47cd8dd5445
parent6a76e84f555da6d9ee57db80143e1e5eb85535ff (diff)
patch 9.0.0198: ml_get error when switching buffer in Visual modev9.0.0198
Problem: ml_get error when switching buffer in Visual mode. Solution: End Visual mode when switching buffer. (closes #10902)
-rw-r--r--src/buffer.c8
-rw-r--r--src/testdir/test_visual.vim20
-rw-r--r--src/version.c2
3 files changed, 30 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 108d596769..669cfa9a97 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1818,6 +1818,14 @@ set_curbuf(buf_T *buf, int action)
static void
enter_buffer(buf_T *buf)
{
+ // when closing the current buffer stop Visual mode
+ if (VIsual_active
+#if defined(EXITFREE)
+ && !entered_free_all_mem
+#endif
+ )
+ end_visual_mode();
+
// Get the buffer in the current window.
curwin->w_buffer = buf;
curbuf = buf;
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
index e965266540..cde70bd1c6 100644
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -1481,5 +1481,25 @@ func Test_visual_area_adjusted_when_hiding()
bwipe!
endfunc
+func Test_switch_buffer_ends_visual_mode()
+ enew
+ call setline(1, 'foo')
+ set hidden
+ set virtualedit=all
+ let buf1 = bufnr()
+ enew
+ let buf2 = bufnr()
+ call setline(1, ['', '', '', ''])
+ call cursor(4, 5)
+ call feedkeys("\<C-V>3k4h", 'xt')
+ exe 'buffer' buf1
+ call assert_equal('n', mode())
+
+ set nohidden
+ set virtualedit=
+ bwipe!
+ exe 'bwipe!' buf2
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 08dc889a92..3f4c7edb87 100644
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 198,
+/**/
197,
/**/
196,