]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1916: WinEnter autocommand confuses Vim when closing tabpage v9.1.1916
authorChristian Brabandt <cb@256bit.org>
Sat, 15 Nov 2025 17:30:58 +0000 (17:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 15 Nov 2025 17:32:50 +0000 (17:32 +0000)
Problem:  WinEnter autocommand may confuse Vim when closing tabpage
          (hokorobi)
Solution: Verify that curwin did not change in close_others()

fixes: #18722
closes: #18733

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_autocmd.vim
src/version.c
src/window.c

index 6957c2a9b63e4b5f0c50c026091e98af11e62ad6..96b076b5eecf6fe220a5afe8abc9cb36518078ba 100644 (file)
@@ -5537,4 +5537,27 @@ func Test_VimResized_and_window_width_not_equalized()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_win_tabclose_autocmd()
+
+  defer CleanUpTestAuGroup()
+  new
+  augroup testing
+    au WinClosed * wincmd p
+  augroup END
+
+  tabnew
+  new
+  new
+
+  call assert_equal(2, tabpagenr('$'))
+  try
+    tabclose
+  catch
+    " should not happen
+    call assert_report("closing tabpage failed")
+  endtry
+  call assert_equal(1, tabpagenr('$'))
+  bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index f501001bb393818780d11d33954dbd5984ba3401..df95ec5067cf9981a89c2de36b593ecf960f910a 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1916,
 /**/
     1915,
 /**/
index 7ff22828031e312b660dac64dd107a3d97b6ca04..28c68800c0285332a88c234e3d94c8fbd601cae1 100644 (file)
@@ -4403,6 +4403,7 @@ close_others(
 {
     win_T      *wp;
     win_T      *nextwp;
+    win_T      *old_curwin = curwin;
     int                r;
 
     if (one_window())
@@ -4416,6 +4417,14 @@ close_others(
     for (wp = firstwin; win_valid(wp); wp = nextwp)
     {
        nextwp = wp->w_next;
+
+       // autocommands messed this one up
+       if (old_curwin != curwin && win_valid(old_curwin))
+       {
+           curwin = old_curwin;
+           curbuf = curwin->w_buffer;
+       }
+
        if (wp == curwin)               // don't close current window
            continue;