]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4996: setbufline() may change Visual selection v8.2.4996
authorBram Moolenaar <Bram@vim.org>
Sun, 22 May 2022 10:59:25 +0000 (11:59 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 22 May 2022 10:59:25 +0000 (11:59 +0100)
Problem:    setbufline() may change Visual selection. (Qiming Zhao)
Solution:   Disable Visual mode when using another buffer. (closes #10466)

src/evalbuffer.c
src/testdir/test_bufline.vim
src/version.c

index 1b829848fb857876b6f902330dee45060b5b411a..13f813ebd8cf7142d1da9a831e0798c2b5c8fcb9 100644 (file)
@@ -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
@@ -158,6 +159,7 @@ set_buffer_lines(
 
     if (!is_curbuf)
     {
+       VIsual_active = FALSE;
        curbuf_save = curbuf;
        curwin_save = curwin;
        curbuf = buf;
@@ -264,6 +266,7 @@ done:
     {
        curbuf = curbuf_save;
        curwin = curwin_save;
+       VIsual_active = save_VIsual_active;
     }
 }
 
index 3acf7c96cd872447b996ed9688ee872c49ff030f..d5b5d7ad848d0704f4bcbcea3dff1d08a2e9c3ad 100644 (file)
@@ -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
index 1a39c062552e6bac093ac1fa1a1874c1e44ea166..fdbb994a4f31117cdfce018a04922ac5f0eba954 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4996,
 /**/
     4995,
 /**/