Skip to content

Commit

Permalink
patch 8.2.4996: setbufline() may change Visual selection
Browse files Browse the repository at this point in the history
Problem:    setbufline() may change Visual selection. (Qiming Zhao)
Solution:   Disable Visual mode when using another buffer. (closes #10466)
  • Loading branch information
brammool committed May 22, 2022
1 parent dafef51 commit 0ad00a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/evalbuffer.c
Expand Up @@ -144,6 +144,7 @@ set_buffer_lines(
buf_T *curbuf_save = NULL;
win_T *curwin_save = NULL;
int is_curbuf = buf == curbuf;
int save_VIsual_active = VIsual_active;

// 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
Expand All @@ -158,6 +159,7 @@ set_buffer_lines(

if (!is_curbuf)
{
VIsual_active = FALSE;
curbuf_save = curbuf;
curwin_save = curwin;
curbuf = buf;
Expand Down Expand Up @@ -264,6 +266,7 @@ set_buffer_lines(
{
curbuf = curbuf_save;
curwin = curwin_save;
VIsual_active = save_VIsual_active;
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/testdir/test_bufline.vim
Expand Up @@ -222,4 +222,20 @@ func Test_appendbufline_redraw()
call delete('XscriptMatchCommon')
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

" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -734,6 +734,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4996,
/**/
4995,
/**/
Expand Down

0 comments on commit 0ad00a7

Please sign in to comment.