Skip to content

Commit d4110e0

Browse files
seandewarchrisbra
authored andcommitted
patch 9.1.1380: 'eventignorewin' only checked for current buffer
Problem: When an autocommand executes for a non-current buffer, 'eventignorewin' is only checked from the buffer's last wininfo (overwrites win_ignore in the loop), not from the value of 'eventignorewin' in all windows showing the buffer as described (after v9.1.1084) Solution: Fix the check and don't use wininfo, as that may only contain windows that recently showed the buffer. Consider all the buffer's windows in all tabpages (Sean Dewar). closes: #17294 Signed-off-by: Sean Dewar <6256228+seandewar@users.noreply.github.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7344024 commit d4110e0

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

src/autocmd.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,16 +2135,24 @@ apply_autocmds_group(
21352135
if (event_ignored(event, p_ei))
21362136
goto BYPASS_AU;
21372137

2138-
wininfo_T *wip;
21392138
int win_ignore = FALSE;
21402139
// If event is allowed in 'eventignorewin', check if curwin or all windows
21412140
// into "buf" are ignoring the event.
21422141
if (buf == curbuf && event_tab[event].key <= 0)
21432142
win_ignore = event_ignored(event, curwin->w_p_eiw);
2144-
else if (buf != NULL && event_tab[event].key <= 0)
2145-
FOR_ALL_BUF_WININFO(buf, wip)
2146-
if (wip->wi_win != NULL && wip->wi_win->w_buffer == buf)
2147-
win_ignore = event_ignored(event, wip->wi_win->w_p_eiw);
2143+
else if (buf != NULL && event_tab[event].key <= 0 && buf->b_nwindows > 0)
2144+
{
2145+
tabpage_T *tp;
2146+
win_T *wp;
2147+
2148+
win_ignore = TRUE;
2149+
FOR_ALL_TAB_WINDOWS(tp, wp)
2150+
if (wp->w_buffer == buf && !event_ignored(event, wp->w_p_eiw))
2151+
{
2152+
win_ignore = FALSE;
2153+
break;
2154+
}
2155+
}
21482156
if (win_ignore)
21492157
goto BYPASS_AU;
21502158

src/testdir/test_autocmd.vim

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,4 +5314,80 @@ func Test_autocmd_tabclosedpre()
53145314
bw!
53155315
endfunc
53165316

5317+
func Test_eventignorewin_non_current()
5318+
defer CleanUpTestAuGroup()
5319+
let s:triggered = ''
5320+
augroup testing
5321+
" Will set <abuf> to the buffer of the closing window.
5322+
autocmd WinClosed * let s:triggered = 'WinClosed'
5323+
augroup END
5324+
let initial_win = win_getid()
5325+
5326+
new
5327+
let new_buf = bufnr()
5328+
" Only set for one of the windows into the new buffer.
5329+
setlocal eventignorewin=all
5330+
split
5331+
setlocal eventignorewin=
5332+
let close_winnr = winnr()
5333+
5334+
" Return to the window where the buffer is non-current. WinClosed should
5335+
" trigger as not all windows into new_buf have 'eventignorewin' set for it.
5336+
call win_gotoid(initial_win)
5337+
call assert_notequal(new_buf, bufnr())
5338+
execute close_winnr 'close'
5339+
call assert_equal('WinClosed', s:triggered)
5340+
5341+
wincmd w
5342+
call assert_equal(new_buf, bufnr())
5343+
tab split
5344+
setlocal eventignorewin=
5345+
let close_winnr = win_getid()
5346+
5347+
" Ensure that new_buf's window in the other tabpage with 'eventignorewin'
5348+
" unset allows WinClosed to run when new_buf is non-current.
5349+
call win_gotoid(initial_win)
5350+
call assert_notequal(new_buf, bufnr())
5351+
let s:triggered = ''
5352+
only!
5353+
call assert_equal('WinClosed', s:triggered)
5354+
call assert_equal(1, win_findbuf(new_buf)->len())
5355+
5356+
" Create an only window to new_buf with 'eventignorewin' set.
5357+
tabonly!
5358+
execute new_buf 'sbuffer'
5359+
setlocal eventignorewin=all
5360+
wincmd p
5361+
call assert_equal(1, win_findbuf(new_buf)->len())
5362+
call assert_notequal(new_buf, bufnr())
5363+
5364+
" Closing a window unrelated to new_buf should not block WinClosed.
5365+
split
5366+
let s:triggered = ''
5367+
close
5368+
call assert_equal('WinClosed', s:triggered)
5369+
call assert_equal(1, win_findbuf(new_buf)->len())
5370+
5371+
" Check WinClosed is blocked when we close the only window to new_buf (that
5372+
" has 'eventignorewin' set) while new_buf is non-current.
5373+
call assert_notequal(new_buf, bufnr())
5374+
let s:triggered = ''
5375+
only!
5376+
call assert_equal('', s:triggered)
5377+
call assert_equal(0, win_findbuf(new_buf)->len())
5378+
5379+
augroup testing
5380+
autocmd!
5381+
autocmd BufNew * ++once let s:triggered = 'BufNew'
5382+
augroup END
5383+
5384+
" Buffer not shown in a window, 'eventignorewin' should not block (and
5385+
" can't even be set for it anyway in this case).
5386+
badd foo
5387+
call assert_equal('BufNew', s:triggered)
5388+
5389+
unlet! s:triggered
5390+
%bw!
5391+
endfunc
5392+
53175393
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1380,
707709
/**/
708710
1379,
709711
/**/

0 commit comments

Comments
 (0)