]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0961: using deletebufline() may jump to another window v9.0.0961
authorBram Moolenaar <Bram@vim.org>
Sun, 27 Nov 2022 19:45:49 +0000 (19:45 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 27 Nov 2022 19:45:49 +0000 (19:45 +0000)
Problem:    Using deletebufline() may jump to another window.
Solution:   Do not use a window where the buffer was only in the past.
            (closes #11594)

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

index 52662a65330c420aa96e8cd3f48d137c638f70bc..82a10d675c9279792d5bf98c8cb96d90c23a76af 100644 (file)
@@ -109,9 +109,12 @@ find_win_for_curbuf(void)
 {
     wininfo_T *wip;
 
+    // The b_wininfo list should have the windows that recently contained the
+    // buffer, going over this is faster than going over all the windows.
+    // Do check the buffer is still there.
     FOR_ALL_BUF_WININFO(curbuf, wip)
     {
-       if (wip->wi_win != NULL)
+       if (wip->wi_win != NULL && wip->wi_win->w_buffer == curbuf)
        {
            curwin = wip->wi_win;
            break;
index 9e4402f79e1eeb92dff8d9868f3e0c104cbe549c..4ada241d1dbc8ec691fa8b31f12758626c89189e 100644 (file)
@@ -288,6 +288,20 @@ func Test_deletebufline_select_mode()
   bwipe!
 endfunc
 
+func Test_deletebufline_popup_window()
+  let popupID = popup_create('foo', {})
+  let bufnr = winbufnr(popupID)
+
+  " Check that deletebufline() brings us back to the same window.
+  new
+  let winid_before = win_getid()
+  call deletebufline(bufnr, 1, '$')
+  call assert_equal(winid_before, win_getid())
+  bwipe
+
+  call popup_close(popupID)
+endfunc
+
 func Test_setbufline_startup_nofile()
   let before =<< trim [CODE]
     set shortmess+=F
index a9a0c72a0c5ba03032b4a5e8e670a4a7ea10e4cd..ecc4da430e3199da6e85af874be837cade93923a 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    961,
 /**/
     960,
 /**/