patch 9.1.2136: :tab sbuffer may close old tabpage

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>
This commit is contained in:
zeertzjq
2026-02-07 10:20:51 +00:00
committed by Christian Brabandt
parent 7ccb81bdb6
commit 6da9f757c4
5 changed files with 45 additions and 4 deletions
+6 -1
View 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
+3 -2
View 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())
+1 -1
View 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
+33
View 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
+2
View File
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2136,
/**/
2135,
/**/