Merge pull request #18691 from zeertzjq/vim-8.2.4996

vim-patch:8.2.{4996.5002}: setbufline(), deletebufline() may change Visual selection
This commit is contained in:
zeertzjq 2022-05-23 07:27:26 +08:00 committed by GitHub
commit a7e0a02031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View File

@ -6886,6 +6886,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T
buf_T *curbuf_save = NULL; buf_T *curbuf_save = NULL;
win_T *curwin_save = NULL; win_T *curwin_save = NULL;
const bool is_curbuf = buf == curbuf; const bool is_curbuf = buf == curbuf;
const bool save_VIsual_active = VIsual_active;
// When using the current buffer ml_mfp will be set if needed. Useful when // When using the current buffer ml_mfp will be set if needed. Useful when
// setline() is used on startup. For other buffers the buffer must be // setline() is used on startup. For other buffers the buffer must be
@ -6896,6 +6897,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T
} }
if (!is_curbuf) { if (!is_curbuf) {
VIsual_active = false;
curbuf_save = curbuf; curbuf_save = curbuf;
curwin_save = curwin; curwin_save = curwin;
curbuf = buf; curbuf = buf;
@ -6986,6 +6988,7 @@ void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, const typval_T
if (!is_curbuf) { if (!is_curbuf) {
curbuf = curbuf_save; curbuf = curbuf_save;
curwin = curwin_save; curwin = curwin_save;
VIsual_active = save_VIsual_active;
} }
} }

View File

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

View File

@ -153,3 +153,38 @@ func Test_appendbufline_redraw()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('XscriptMatchCommon') call delete('XscriptMatchCommon')
endfunc endfunc
func Test_setbufline_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'])
call feedkeys("x", 'nx')
call assert_equal(['foo', 'x'], getline(1, 2))
exe "bwipe! " .. bufnr
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