]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1393: missing test for switching buffers and reusing curbuf v9.1.1393
authorSean Dewar <6256228+seandewar@users.noreply.github.com>
Thu, 15 May 2025 17:59:37 +0000 (19:59 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 15 May 2025 17:59:37 +0000 (19:59 +0200)
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>
src/buffer.c
src/testdir/test_autocmd.vim
src/version.c

index 49ec77c7b15e2bc29bacb5ce224d96f0dd4a86f8..48e8cb63bc176647832a344d7129aa3860fb5643 100644 (file)
@@ -909,7 +909,7 @@ buf_freeall(buf_T *buf, int flags)
     // If the buffer was in curwin and the window has changed, go back to that
     // window, if it still exists.  This avoids that ":edit x" triggering a
     // "tabnext" BufUnload autocmd leaves a window behind without a buffer.
-    if (is_curwin && curwin != the_curwin &&  win_valid_any_tab(the_curwin))
+    if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
     {
        block_autocmds();
        goto_tabpage_win(the_curtab, the_curwin);
index 26f714565285244002e093351522ef3137e2844a..1988807f75c66cf34d4e8eb929b8f99ba1e49fc9 100644 (file)
@@ -5415,4 +5415,31 @@ func Test_reuse_curbuf_leak()
   %bw!
 endfunc
 
+func Test_reuse_curbuf_switch()
+  edit asdf
+  let s:asdf_win = win_getid()
+  new
+  let other_buf = bufnr()
+  let other_win = win_getid()
+  augroup testing
+    autocmd!
+    autocmd BufUnload * ++once let s:triggered = 1
+          \| call assert_fails('split', 'E1159:')
+          \| call win_gotoid(s:asdf_win)
+  augroup END
+
+  " Check BufUnload changing curbuf does not cause buflist_new to create a new
+  " buffer while leaving "other_buf" unloaded in a window.
+  enew
+  call assert_equal(1, s:triggered)
+  call assert_equal(other_buf, bufnr())
+  call assert_equal(other_win, win_getid())
+  call assert_equal(1, win_findbuf(other_buf)->len())
+  call assert_equal(1, bufloaded(other_buf))
+
+  unlet! s:asdf_win s:triggered
+  call CleanUpTestAuGroup()
+  %bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index e4651653ba6c551c91600719d7fbb14184ec30b4..ffcfccb2dc7b2b5f90f08f79c56b0770aa7be800 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1393,
 /**/
     1392,
 /**/