aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-13 21:47:52 +0800
committerGitHub <noreply@github.com>2022-08-13 21:47:52 +0800
commit3cf629022b6289a980c47cfae921f9aec1948585 (patch)
tree238ad3b9e8f689ada1609a18153693bd07c37d11
parentf9a9956837223b45a266c6cd3294caeb25be5972 (diff)
downloadrneovim-3cf629022b6289a980c47cfae921f9aec1948585.tar.gz
rneovim-3cf629022b6289a980c47cfae921f9aec1948585.tar.bz2
rneovim-3cf629022b6289a980c47cfae921f9aec1948585.zip
vim-patch:9.0.0198: ml_get error when switching buffer in Visual mode (#19756)
Problem: ml_get error when switching buffer in Visual mode. Solution: End Visual mode when switching buffer. (closes vim/vim#10902) https://github.com/vim/vim/commit/cfeb8a584be11758cf71ae02f6c937b06d6bb66f
-rw-r--r--src/nvim/buffer.c9
-rw-r--r--src/nvim/testdir/test_visual.vim20
2 files changed, 29 insertions, 0 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index ce788cc7a0..be376c2109 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1533,6 +1533,15 @@ void set_curbuf(buf_T *buf, int action)
/// be pointing to freed memory.
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/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim
index f9ac0e0884..b6a8fb24a4 100644
--- a/src/nvim/testdir/test_visual.vim
+++ b/src/nvim/testdir/test_visual.vim
@@ -1550,5 +1550,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