Skip to content

Commit

Permalink
patch 8.2.5002: deletebufline() may change Visual selection
Browse files Browse the repository at this point in the history
Problem:    deletebufline() may change Visual selection.
Solution:   Disable Visual mode when using another buffer. (closes #10469)
  • Loading branch information
LemonBoy authored and brammool committed May 22, 2022
1 parent 8a37047 commit 9b2edfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/evalbuffer.c
Expand Up @@ -510,6 +510,7 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
tabpage_T *tp;
win_T *wp;
int did_emsg_before = did_emsg;
int save_VIsual_active = VIsual_active;

rettv->vval.v_number = 1; // FAIL by default

Expand Down Expand Up @@ -538,6 +539,7 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)

if (!is_curbuf)
{
VIsual_active = FALSE;
curbuf_save = curbuf;
curwin_save = curwin;
curbuf = buf;
Expand Down Expand Up @@ -582,6 +584,7 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
{
curbuf = curbuf_save;
curwin = curwin_save;
VIsual_active = save_VIsual_active;
}
rettv->vval.v_number = 0; // OK
}
Expand Down
17 changes: 17 additions & 0 deletions src/testdir/test_bufline.vim
Expand Up @@ -238,4 +238,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
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 */
/**/
5002,
/**/
5001,
/**/
Expand Down

0 comments on commit 9b2edfd

Please sign in to comment.