]> granicus.if.org Git - vim/commitdiff
patch 9.0.0198: ml_get error when switching buffer in Visual mode v9.0.0198
authorBram Moolenaar <Bram@vim.org>
Sat, 13 Aug 2022 13:09:44 +0000 (14:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 13 Aug 2022 13:09:44 +0000 (14:09 +0100)
Problem:    ml_get error when switching buffer in Visual mode.
Solution:   End Visual mode when switching buffer. (closes #10902)

src/buffer.c
src/testdir/test_visual.vim
src/version.c

index 108d5967695105101887d52ecb4290effc263846..669cfa9a9785bdc217ee18d17081a2e98a51645e 100644 (file)
@@ -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;
index e965266540068bc46eb69008610cb5eceef34e84..cde70bd1c6ec1ff09a28dc849f03eb2e308697a0 100644 (file)
@@ -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
index 08dc889a92b3e9f5be567dde7117d61522f5f1be..3f4c7edb874612c575fd02e04c8a15539d1d3cbe 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    198,
 /**/
     197,
 /**/