Skip to content

Commit 31be82e

Browse files
seandewarchrisbra
authored andcommitted
patch 9.1.1393: missing test for switching buffers and reusing curbuf
Problem: The check in buf_freeall that restores curwin subtly prevents leaving an unloaded buffer in a window when reusing curbuf, if autocommands switch to a different buffer. Solution: Add a test case that covers this. Also ensure splitting isn't possible, as that could do the same (Sean Dewar) closes: #17325 Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent c49cb93 commit 31be82e

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ buf_freeall(buf_T *buf, int flags)
909909
// If the buffer was in curwin and the window has changed, go back to that
910910
// window, if it still exists. This avoids that ":edit x" triggering a
911911
// "tabnext" BufUnload autocmd leaves a window behind without a buffer.
912-
if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
912+
if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
913913
{
914914
block_autocmds();
915915
goto_tabpage_win(the_curtab, the_curwin);

src/testdir/test_autocmd.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5415,4 +5415,31 @@ func Test_reuse_curbuf_leak()
54155415
%bw!
54165416
endfunc
54175417

5418+
func Test_reuse_curbuf_switch()
5419+
edit asdf
5420+
let s:asdf_win = win_getid()
5421+
new
5422+
let other_buf = bufnr()
5423+
let other_win = win_getid()
5424+
augroup testing
5425+
autocmd!
5426+
autocmd BufUnload * ++once let s:triggered = 1
5427+
\| call assert_fails('split', 'E1159:')
5428+
\| call win_gotoid(s:asdf_win)
5429+
augroup END
5430+
5431+
" Check BufUnload changing curbuf does not cause buflist_new to create a new
5432+
" buffer while leaving "other_buf" unloaded in a window.
5433+
enew
5434+
call assert_equal(1, s:triggered)
5435+
call assert_equal(other_buf, bufnr())
5436+
call assert_equal(other_win, win_getid())
5437+
call assert_equal(1, win_findbuf(other_buf)->len())
5438+
call assert_equal(1, bufloaded(other_buf))
5439+
5440+
unlet! s:asdf_win s:triggered
5441+
call CleanUpTestAuGroup()
5442+
%bw!
5443+
endfunc
5444+
54185445
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ static char *(features[]) =
709709

710710
static int included_patches[] =
711711
{ /* Add new patch number below this line */
712+
/**/
713+
1393,
712714
/**/
713715
1392,
714716
/**/

0 commit comments

Comments
 (0)