vim-patch:8.2.5002: deletebufline() may change Visual selection

Problem:    deletebufline() may change Visual selection.
Solution:   Disable Visual mode when using another buffer. (closes vim/vim#10469)
9b2edfd3bf
This commit is contained in:
zeertzjq 2022-05-23 06:54:27 +08:00
parent eae4eddc54
commit bcfc97e8d8
2 changed files with 20 additions and 0 deletions

View File

@ -1636,6 +1636,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return;
}
const bool is_curbuf = buf == curbuf;
const bool save_VIsual_active = VIsual_active;
const linenr_T first = tv_get_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type != VAR_UNKNOWN) {
@ -1651,6 +1652,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
if (!is_curbuf) {
VIsual_active = false;
curbuf_save = curbuf;
curwin_save = curwin;
curbuf = buf;
@ -1694,6 +1696,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (!is_curbuf) {
curbuf = curbuf_save;
curwin = curwin_save;
VIsual_active = save_VIsual_active;
}
}

View File

@ -170,4 +170,21 @@ func Test_setbufline_select_mode()
bwipe!
endfunc
func Test_deletebufline_select_mode()
new
call setline(1, ['foo', 'bar'])
call feedkeys("j^v2l\<C-G>", 'nx')
let bufnr = bufadd('Xdummy')
call bufload(bufnr)
call setbufline(bufnr, 1, ['abc', 'def'])
call deletebufline(bufnr, 1)
call feedkeys("x", 'nx')
call assert_equal(['foo', 'x'], getline(1, 2))
exe "bwipe! " .. bufnr
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab