]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4475: fuzzy cmdline completion does not work for lower case v8.2.4475
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 26 Feb 2022 11:04:42 +0000 (11:04 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Feb 2022 11:04:42 +0000 (11:04 +0000)
Problem:    Fuzzy cmdline completion does not work for lower case.
Solution:   Also use fuzzy completion for lower case input. (Yegappan
            Lakshmanan, closes #9849)

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

index 94781f82f0643b4f3beda0a42bb9068d15c76ebc..138ff9ef814bd5ff5b736d5ff0e4bb3e67853888 100644 (file)
@@ -1212,6 +1212,7 @@ set_cmd_index(char_u *cmd, exarg_T *eap, expand_T *xp, int *complp)
 {
     char_u     *p = NULL;
     int                len = 0;
+    int                fuzzy = cmdline_fuzzy_complete(cmd);
 
     // Isolate the command and search for it in the command table.
     // Exceptions:
@@ -1253,7 +1254,9 @@ set_cmd_index(char_u *cmd, exarg_T *eap, expand_T *xp, int *complp)
 
        eap->cmdidx = excmd_get_cmdidx(cmd, len);
 
-       if (cmd[0] >= 'A' && cmd[0] <= 'Z')
+       // User defined commands support alphanumeric characters.
+       // Also when doing fuzzy expansion, support alphanumeric characters.
+       if ((cmd[0] >= 'A' && cmd[0] <= 'Z') || (fuzzy && *p != NUL))
            while (ASCII_ISALNUM(*p) || *p == '*')      // Allow * wild card
                ++p;
     }
@@ -2493,6 +2496,7 @@ ExpandFromContext(
     int                ret;
     int                flags;
     char_u     *tofree = NULL;
+    int                fuzzy = cmdline_fuzzy_complete(pat);
 
     flags = map_wildopts_to_ewflags(options);
 
@@ -2577,12 +2581,15 @@ ExpandFromContext(
        pat = tofree;
     }
 
-    regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
-    if (regmatch.regprog == NULL)
-       return FAIL;
+    if (!fuzzy)
+    {
+       regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0);
+       if (regmatch.regprog == NULL)
+           return FAIL;
 
-    // set ignore-case according to p_ic, p_scs and pat
-    regmatch.rm_ic = ignorecase(pat);
+       // set ignore-case according to p_ic, p_scs and pat
+       regmatch.rm_ic = ignorecase(pat);
+    }
 
     if (xp->xp_context == EXPAND_SETTINGS
            || xp->xp_context == EXPAND_BOOL_SETTINGS)
@@ -2596,7 +2603,8 @@ ExpandFromContext(
     else
        ret = ExpandOther(pat, xp, &regmatch, matches, numMatches);
 
-    vim_regfree(regmatch.regprog);
+    if (!fuzzy)
+       vim_regfree(regmatch.regprog);
     vim_free(tofree);
 
     return ret;
index 73d39e39e083fd944b808cdf5f20ab645c47c598..c83a8f14700205065d350b51abf75558f71bd9b0 100644 (file)
@@ -2776,6 +2776,18 @@ func Test_wildoptions_fuzzy()
   delcommand T123FendingOff
   %bw
 
+  " Test for fuzzy completion of a command with lower case letters and a
+  " number
+  command Foo2Bar :
+  set wildoptions=fuzzy
+  call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"Foo2Bar', @:)
+  call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"Foo2Bar', @:)
+  call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
+  call assert_equal('"Foo2Bar', @:)
+  delcommand Foo2Bar
+
   set wildoptions&
   %bw!
 endfunc
index c7c7402ea296419e89b8bc070064691f0c1ded18..8842ecca8da9f549b6ef891ccb22bf5924e48722 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4475,
 /**/
     4474,
 /**/