]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2136: :tab sbuffer may close old tabpage v9.1.2136
authorzeertzjq <zeertzjq@outlook.com>
Sat, 7 Feb 2026 10:20:51 +0000 (10:20 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 7 Feb 2026 10:23:41 +0000 (10:23 +0000)
Problem:  :tab sbuffer may close old tabpage if BufLeave autocommand
          splits window (after 9.1.0143).
Solution: Only close other windows if the buffer will be unloaded
          (zeertzjq).

related: neovim/neovim#37749
closes: #19352

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/version9.txt
src/buffer.c
src/testdir/test_autocmd.vim
src/testdir/test_buffer.vim
src/version.c

index 05d4da2be31045780258130fc3389ad4683eb49f..3dd3754b1820ed134d38c05e501a63de050e535d 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt* For Vim version 9.1.  Last change: 2026 Feb 06
+*version9.txt* For Vim version 9.1.  Last change: 2026 Feb 07
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -52502,4 +52502,9 @@ Problem:  search() is used to check for the message from tar that
           src/testdir/samples/evil.tar.
 Solution: Use the 'w' flag for search() (Kevin Goodsell)
 
+Patch 9.1.2136
+Problem:  :tab sbuffer may close old tabpage if BufLeave autocommand
+          splits window (after 9.1.0143).
+Solution: Only close other windows if the buffer will be unloaded (zeertzjq).
+
  vim:tw=78:ts=8:noet:ft=help:norl:fdm=manual:nofoldenable
index 86b784023058c2bb41bf50b3c284fa537a164d38..8a5d883e787670df9e1ea56d6eaef6a1f9e600e4 100644 (file)
@@ -1886,6 +1886,7 @@ set_curbuf(buf_T *buf, int action)
     prevbuf = curbuf;
     set_bufref(&prevbufref, prevbuf);
     set_bufref(&newbufref, buf);
+    int prev_nwindows = prevbuf->b_nwindows;
 
     // Autocommands may delete the current buffer and/or the buffer we want to
     // go to.  In those cases don't close the buffer.
@@ -1904,8 +1905,8 @@ set_curbuf(buf_T *buf, int action)
        // autocommands may have opened a new window
        // with prevbuf, grr
        if (unload ||
-           (last_winid != get_last_winid() &&
-            strchr((char *)"wdu", prevbuf->b_p_bh[0]) != NULL))
+               (prev_nwindows <= 1 && last_winid != get_last_winid()
+                && action == DOBUF_GOTO && !buf_hide(prevbuf)))
            close_windows(prevbuf, FALSE);
 #if defined(FEAT_EVAL)
        if (bufref_valid(&prevbufref) && !aborting())
index 82d62e7636d954ac51925a4c4e9b35f0018e9987..74b1aabdf369597ab9b4760b4c006876d6c7d197 100644 (file)
@@ -4757,7 +4757,7 @@ func Test_autocmd_invalidates_undo_on_textchanged()
   call StopVimInTerminal(buf)
 endfunc
 
-func Test_autocmd_creates_new_buffer_on_bufleave()
+func Test_autocmd_creates_new_window_on_bufleave()
   e a.txt
   e b.txt
   setlocal bufhidden=wipe
index 4ededa15d440d873cc4a1d1a8b735e13f633e3fc..934bc6fe1e8bd714ccae1ab1ada645417e517da6 100644 (file)
@@ -880,4 +880,37 @@ func Test_bdelete_skip_closing_bufs()
   %bw!
 endfunc
 
+func Test_split_window_in_BufLeave_from_tab_sbuffer()
+  tabnew Xa
+  setlocal bufhidden=wipe
+  let t0 = tabpagenr()
+  let b0 = bufnr()
+  let b1 = bufadd('Xb')
+  autocmd BufLeave Xa ++once split
+  exe 'tab sbuffer' b1
+  call assert_equal(t0 + 1, tabpagenr())
+  call assert_equal([b1, b0], tabpagebuflist())
+  call assert_equal([b0], tabpagebuflist(t0))
+  tabclose
+  call assert_equal(t0, tabpagenr())
+  call assert_equal([b0], tabpagebuflist())
+
+  bwipe! Xa
+  bwipe! Xb
+endfunc
+
+func Test_split_window_in_BufLeave_from_switching_buffer()
+  tabnew Xa
+  setlocal bufhidden=wipe
+  split
+  let b0 = bufnr()
+  let b1 = bufadd('Xb')
+  autocmd BufLeave Xa ++once split
+  exe 'buffer' b1
+  call assert_equal([b1, b0, b0], tabpagebuflist())
+
+  bwipe! Xa
+  bwipe! Xb
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 0adf730affa59dabae5c9d1fb936de5e882d861d..8721de4496852a60258680ccd5c30e5e92fed32c 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2136,
 /**/
     2135,
 /**/