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)
cfeb8a584b
This commit is contained in:
zeertzjq
2022-08-13 21:47:52 +08:00
committed by GitHub
parent f9a9956837
commit 3cf629022b
2 changed files with 29 additions and 0 deletions

View File

@@ -1533,6 +1533,15 @@ void set_curbuf(buf_T *buf, int action)
/// be pointing to freed memory. /// be pointing to freed memory.
void enter_buffer(buf_T *buf) 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. // Get the buffer in the current window.
curwin->w_buffer = buf; curwin->w_buffer = buf;
curbuf = buf; curbuf = buf;

View File

@@ -1550,5 +1550,25 @@ func Test_visual_area_adjusted_when_hiding()
bwipe! bwipe!
endfunc 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 " vim: shiftwidth=2 sts=2 expandtab