Skip to content

Commit c10b521

Browse files
committed
patch 8.2.0116: BufEnter autocmd not triggered on ":tab drop"
Problem: BufEnter autocmd not triggered on ":tab drop". (Andy Stewart) Solution: Decrement autocmd_no_enter for the last file. (closes #1660, closes #5473)
1 parent 9df53b6 commit c10b521

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/arglist.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ do_arg_all(
864864
//
865865
int opened_len; // length of opened[]
866866
int use_firstwin = FALSE; // use first window for arglist
867+
int tab_drop_empty_window = FALSE;
867868
int split_ret = OK;
868869
int p_ea_save;
869870
alist_T *alist; // argument list to be used
@@ -1027,13 +1028,16 @@ do_arg_all(
10271028
last_curwin = curwin;
10281029
last_curtab = curtab;
10291030
win_enter(lastwin, FALSE);
1030-
// ":drop all" should re-use an empty window to avoid "--remote-tab"
1031+
// ":tab drop file" should re-use an empty window to avoid "--remote-tab"
10311032
// leaving an empty tab page when executed locally.
10321033
if (keep_tabs && BUFEMPTY() && curbuf->b_nwindows == 1
10331034
&& curbuf->b_ffname == NULL && !curbuf->b_changed)
1035+
{
10341036
use_firstwin = TRUE;
1037+
tab_drop_empty_window = TRUE;
1038+
}
10351039

1036-
for (i = 0; i < count && i < opened_len && !got_int; ++i)
1040+
for (i = 0; i < count && !got_int; ++i)
10371041
{
10381042
if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1)
10391043
arg_had_last = TRUE;
@@ -1067,6 +1071,9 @@ do_arg_all(
10671071
}
10681072
else if (split_ret == OK)
10691073
{
1074+
// trigger events for tab drop
1075+
if (tab_drop_empty_window && i == count - 1)
1076+
--autocmd_no_enter;
10701077
if (!use_firstwin) // split current window
10711078
{
10721079
p_ea_save = p_ea;
@@ -1091,6 +1098,8 @@ do_arg_all(
10911098
((buf_hide(curwin->w_buffer)
10921099
|| bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0)
10931100
+ ECMD_OLDBUF, curwin);
1101+
if (tab_drop_empty_window && i == count - 1)
1102+
++autocmd_no_enter;
10941103
if (use_firstwin)
10951104
++autocmd_no_leave;
10961105
use_firstwin = FALSE;

src/testdir/test_tabpage.vim

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,34 @@ function Test_tabpage_with_autocmd()
222222
1tabonly!
223223
endfunction
224224

225+
" Test autocommands on tab drop
226+
function Test_tabpage_with_autocmd_tab_drop()
227+
augroup TestTabpageGroup
228+
au!
229+
autocmd TabEnter * call add(s:li, 'TabEnter')
230+
autocmd WinEnter * call add(s:li, 'WinEnter')
231+
autocmd BufEnter * call add(s:li, 'BufEnter')
232+
autocmd TabLeave * call add(s:li, 'TabLeave')
233+
autocmd WinLeave * call add(s:li, 'WinLeave')
234+
autocmd BufLeave * call add(s:li, 'BufLeave')
235+
augroup END
236+
237+
let s:li = []
238+
tab drop test1
239+
call assert_equal(['BufLeave', 'BufEnter'], s:li)
240+
241+
let s:li = []
242+
tab drop test2 test3
243+
call assert_equal([
244+
\ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter',
245+
\ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter',
246+
\ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li)
247+
248+
autocmd! TestTabpageGroup
249+
augroup! TestTabpageGroup
250+
1tabonly!
251+
endfunction
252+
225253
function Test_tabpage_with_tab_modifier()
226254
CheckFeature quickfix
227255

src/version.c

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

743743
static int included_patches[] =
744744
{ /* Add new patch number below this line */
745+
/**/
746+
116,
745747
/**/
746748
115,
747749
/**/

0 commit comments

Comments
 (0)