]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0116: BufEnter autocmd not triggered on ":tab drop" v8.2.0116
authorBram Moolenaar <Bram@vim.org>
Mon, 13 Jan 2020 19:54:51 +0000 (20:54 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 13 Jan 2020 19:54:51 +0000 (20:54 +0100)
Problem:    BufEnter autocmd not triggered on ":tab drop". (Andy Stewart)
Solution:   Decrement autocmd_no_enter for the last file. (closes #1660,
            closes #5473)

src/arglist.c
src/testdir/test_tabpage.vim
src/version.c

index b1a6a0b2f59f5cf60d2d8930a74a6e7a24c99f0b..942da86c225c947713c76474256e417542181619 100644 (file)
@@ -864,6 +864,7 @@ do_arg_all(
                                //
     int                opened_len;     // length of opened[]
     int                use_firstwin = FALSE;   // use first window for arglist
+    int                tab_drop_empty_window = FALSE;
     int                split_ret = OK;
     int                p_ea_save;
     alist_T    *alist;         // argument list to be used
@@ -1027,13 +1028,16 @@ do_arg_all(
     last_curwin = curwin;
     last_curtab = curtab;
     win_enter(lastwin, FALSE);
-    // ":drop all" should re-use an empty window to avoid "--remote-tab"
+    // ":tab drop file" should re-use an empty window to avoid "--remote-tab"
     // leaving an empty tab page when executed locally.
     if (keep_tabs && BUFEMPTY() && curbuf->b_nwindows == 1
                            && curbuf->b_ffname == NULL && !curbuf->b_changed)
+    {
        use_firstwin = TRUE;
+       tab_drop_empty_window = TRUE;
+    }
 
-    for (i = 0; i < count && i < opened_len && !got_int; ++i)
+    for (i = 0; i < count && !got_int; ++i)
     {
        if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1)
            arg_had_last = TRUE;
@@ -1067,6 +1071,9 @@ do_arg_all(
        }
        else if (split_ret == OK)
        {
+           // trigger events for tab drop
+           if (tab_drop_empty_window && i == count - 1)
+               --autocmd_no_enter;
            if (!use_firstwin)          // split current window
            {
                p_ea_save = p_ea;
@@ -1091,6 +1098,8 @@ do_arg_all(
                      ((buf_hide(curwin->w_buffer)
                           || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0)
                                                       + ECMD_OLDBUF, curwin);
+           if (tab_drop_empty_window && i == count - 1)
+               ++autocmd_no_enter;
            if (use_firstwin)
                ++autocmd_no_leave;
            use_firstwin = FALSE;
index 392eecbf798c45fcd1e12d15f60c0e1f63ba3c28..bf721a0b61b0f732f26027eb44c647d2776f28ff 100644 (file)
@@ -222,6 +222,34 @@ function Test_tabpage_with_autocmd()
   1tabonly!
 endfunction
 
+" Test autocommands on tab drop
+function Test_tabpage_with_autocmd_tab_drop()
+  augroup TestTabpageGroup
+    au!
+    autocmd TabEnter * call add(s:li, 'TabEnter')
+    autocmd WinEnter * call add(s:li, 'WinEnter')
+    autocmd BufEnter * call add(s:li, 'BufEnter')
+    autocmd TabLeave * call add(s:li, 'TabLeave')
+    autocmd WinLeave * call add(s:li, 'WinLeave')
+    autocmd BufLeave * call add(s:li, 'BufLeave')
+  augroup END
+
+  let s:li = []
+  tab drop test1
+  call assert_equal(['BufLeave', 'BufEnter'], s:li)
+
+  let s:li = []
+  tab drop test2 test3
+  call assert_equal([
+        \ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter',
+        \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter',
+        \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li)
+
+  autocmd! TestTabpageGroup
+  augroup! TestTabpageGroup
+  1tabonly!
+endfunction
+
 function Test_tabpage_with_tab_modifier()
   CheckFeature quickfix
 
index 2d502beac6e3ef5e6227a1c71d2c9ba0874b5278..1e79e03c681101fb35e2ead0d5724bb5b1a78aa7 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    116,
 /**/
     115,
 /**/