]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1636: expanding a pattern interferes with cmdline completion v9.0.1636
authorzeertzjq <zeertzjq@outlook.com>
Thu, 15 Jun 2023 21:51:57 +0000 (22:51 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 15 Jun 2023 21:51:57 +0000 (22:51 +0100)
Problem:    Expanding a pattern interferes with command line completion.
Solution:   Set the file index only when appropriate. (closes #12519)

src/cmdexpand.c
src/testdir/test_cmdline.vim
src/version.c

index 46615383c03f470d61af3fd7c7ad55a4e5e1b3a0..09691066e09d5011b25376b7be4a3940e1619da5 100644 (file)
@@ -957,7 +957,7 @@ ExpandOne(
     int                mode)
 {
     char_u     *ss = NULL;
-    static int findex;
+    static int findex;                 // TODO: Move into expand_T
     static char_u *orig_save = NULL;   // kept value of orig
     int                orig_saved = FALSE;
     int                i;
@@ -971,8 +971,9 @@ ExpandOne(
     if (mode == WILD_CANCEL)
        ss = vim_strsave(orig_save ? orig_save : (char_u *)"");
     else if (mode == WILD_APPLY)
-       ss = vim_strsave(findex == -1 ? (orig_save ?
-                   orig_save : (char_u *)"") : xp->xp_files[findex]);
+       ss = vim_strsave(findex == -1
+                           ? (orig_save ? orig_save : (char_u *)"")
+                           : xp->xp_files[findex]);
 
     // free old names
     if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
@@ -985,7 +986,9 @@ ExpandOne(
        if (compl_match_array != NULL)
            cmdline_pum_remove();
     }
-    findex = 0;
+    // TODO: Remove condition if "findex" is part of expand_T ?
+    if (mode != WILD_EXPAND_FREE && mode != WILD_ALL && mode != WILD_ALL_KEEP)
+       findex = 0;
 
     if (mode == WILD_FREE)     // only release file name
        return NULL;
index 79740b5bb0ae0af9d874ac3e7da4c73249514441..ff38b69c6e3d236a6fcf986cf64f173b8821c948 100644 (file)
@@ -1336,6 +1336,30 @@ func Test_cmdline_complete_various()
   call assert_equal('"py3file', @:)
 endfunc
 
+" Test that expanding a pattern doesn't interfere with cmdline completion.
+func Test_expand_during_cmdline_completion()
+  func ExpandStuff()
+    badd <script>:p:h/README.*
+    call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
+    $bwipe
+    call assert_equal('README.txt', expand('README.*'))
+    call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
+  endfunc
+  augroup test_CmdlineChanged
+    autocmd!
+    autocmd CmdlineChanged * call ExpandStuff()
+  augroup END
+
+  call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
+  call assert_equal('"sign place', @:)
+
+  augroup test_CmdlineChanged
+    au!
+  augroup END
+  augroup! test_CmdlineChanged
+  delfunc ExpandStuff
+endfunc
+
 " Test for 'wildignorecase'
 func Test_cmdline_wildignorecase()
   CheckUnix
@@ -1675,6 +1699,7 @@ func Test_cmd_bang_E135()
   augroup test_cmd_filter_E135
     au!
   augroup END
+  augroup! test_cmd_filter_E135
   %bwipe!
 endfunc
 
@@ -2134,7 +2159,7 @@ endfunc
 func Test_cmd_map_cmdlineChanged()
   let g:log = []
   cnoremap <F1> l<Cmd><CR>s
-  augroup test
+  augroup test_CmdlineChanged
     autocmd!
     autocmd CmdlineChanged : let g:log += [getcmdline()]
   augroup END
@@ -2150,9 +2175,10 @@ func Test_cmd_map_cmdlineChanged()
 
   unlet g:log
   cunmap <F1>
-  augroup test
+  augroup test_CmdlineChanged
     autocmd!
   augroup END
+  augroup! test_CmdlineChanged
 endfunc
 
 " Test for the 'suffixes' option
index 2665c51090652cca396eb03cc486b70d79be03e0..6a70e21b7b28267cedfa25da0fe899c3d0603ba8 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1636,
 /**/
     1635,
 /**/