Skip to content

Commit 61b73b8

Browse files
committed
patch 9.1.1916: WinEnter autocommand confuses Vim when closing tabpage
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 <[email protected]>
1 parent fb8ebf1 commit 61b73b8

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/testdir/test_autocmd.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5537,4 +5537,27 @@ func Test_VimResized_and_window_width_not_equalized()
55375537
call StopVimInTerminal(buf)
55385538
endfunc
55395539

5540+
func Test_win_tabclose_autocmd()
5541+
5542+
defer CleanUpTestAuGroup()
5543+
new
5544+
augroup testing
5545+
au WinClosed * wincmd p
5546+
augroup END
5547+
5548+
tabnew
5549+
new
5550+
new
5551+
5552+
call assert_equal(2, tabpagenr('$'))
5553+
try
5554+
tabclose
5555+
catch
5556+
" should not happen
5557+
call assert_report("closing tabpage failed")
5558+
endtry
5559+
call assert_equal(1, tabpagenr('$'))
5560+
bw!
5561+
endfunc
5562+
55405563
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1916,
732734
/**/
733735
1915,
734736
/**/

src/window.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,6 +4403,7 @@ close_others(
44034403
{
44044404
win_T *wp;
44054405
win_T *nextwp;
4406+
win_T *old_curwin = curwin;
44064407
int r;
44074408

44084409
if (one_window())
@@ -4416,6 +4417,14 @@ close_others(
44164417
for (wp = firstwin; win_valid(wp); wp = nextwp)
44174418
{
44184419
nextwp = wp->w_next;
4420+
4421+
// autocommands messed this one up
4422+
if (old_curwin != curwin && win_valid(old_curwin))
4423+
{
4424+
curwin = old_curwin;
4425+
curbuf = curwin->w_buffer;
4426+
}
4427+
44194428
if (wp == curwin) // don't close current window
44204429
continue;
44214430

0 commit comments

Comments
 (0)