]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1197: process_next_cpt_value() uses wrong condition v9.1.1197
authorglepnir <glephunter@gmail.com>
Wed, 12 Mar 2025 20:28:39 +0000 (21:28 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 12 Mar 2025 20:28:39 +0000 (21:28 +0100)
Problem:  process_next_cpt_value() uses wrong condition
Solution: use cfc_has_mode() instead and remove redundant else if branch
          (glepnir)

closes: #16833

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/options.txt
src/insexpand.c
src/search.c
src/testdir/test_ins_complete.vim
src/version.c

index 588daf643627c718bb5fcaf80862e8e9e8da9615..c2ad86e0ed9cb05c8736a2625c4a10559f13e6bb 100644 (file)
@@ -1,4 +1,4 @@
-*options.txt*  For Vim version 9.1.  Last change: 2025 Mar 07
+*options.txt*  For Vim version 9.1.  Last change: 2025 Mar 12
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -2107,14 +2107,23 @@ A jump table for the options with a short description can be found at |Q_op|.
                                                *'completefuzzycollect'* *'cfc'*
 'completefuzzycollect' 'cfc'   string  (default: empty)
                                global
-       This option enables fuzzy collection for (only some) specific
-       |ins-completion| modes, adjusting how items are gathered for fuzzy
-       matching based on input.
-       The option can contain the following values (separated by commas),
-       each enabling fuzzy collection for a specific completion mode:
-       files           file names
-       keyword         keyword completion in 'complete' and current file
-       whole_line      whole lines
+       A comma-separated list of option enables fuzzy collection for specific
+       |ins-completion| modes, affecting how items are gathered during
+       completion. When set, fuzzy matching is used to find completion
+       candidates instead of the standard prefix-based matching. This option
+       can contain the following values are:
+
+       keyword         keywords in the current file |i_CTRL-X_CTRL-N|
+                       keywords with the ".", "w", "b", "u", "U" and
+                       "k{dict}" flags in 'complete'. |i_CTRL-N| |i_CTRL-P|
+
+       files           file names  |i_CTRL-X_CTRL-F|
+
+       whole_line      whole lines |i_CTRL-X_CTRL-L|
+
+       When used with 'completeopt' "longest" option, fuzzy collection can
+       identify the longest common string among the best fuzzy matches and
+       automatically insert it.
 
                                                *'completeitemalign'* *'cia'*
 'completeitemalign' 'cia' string (default: "abbr,kind,menu")
index d8bb0814d3f40a99877e5a59f00c957e0ea1e4b4..35d20d01d6e8b38b4f9870881b7d072a9a11dfd2 100644 (file)
@@ -3671,7 +3671,7 @@ process_next_cpt_value(
        ins_compl_next_state_T *st,
        int             *compl_type_arg,
        pos_T           *start_match_pos,
-       int             in_fuzzy)
+       int             fuzzy_collect)
 {
     int            compl_type = -1;
     int            status = INS_COMPL_CPT_OK;
@@ -3687,7 +3687,7 @@ process_next_cpt_value(
        st->first_match_pos = *start_match_pos;
        // Move the cursor back one character so that ^N can match the
        // word immediately after the cursor.
-       if (ctrl_x_mode_normal() && (!in_fuzzy && dec(&st->first_match_pos) < 0))
+       if (ctrl_x_mode_normal() && (!fuzzy_collect && dec(&st->first_match_pos) < 0))
        {
            // Move the cursor to after the last character in the
            // buffer, so that word at start of buffer is found
@@ -4487,7 +4487,6 @@ ins_compl_get_exp(pos_T *ini)
     int                i;
     int                found_new_match;
     int                type = ctrl_x_mode;
-    int                in_fuzzy = (get_cot_flags() & COT_FUZZY) != 0;
 
     if (!compl_started)
     {
@@ -4528,7 +4527,7 @@ ins_compl_get_exp(pos_T *ini)
        if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval())
                                        && (!compl_started || st.found_all))
        {
-           int status = process_next_cpt_value(&st, &type, ini, in_fuzzy);
+           int status = process_next_cpt_value(&st, &type, ini, cfc_has_mode());
 
            if (status == INS_COMPL_CPT_END)
                break;
index 654b8968b56c5848b2696bd5e40c0c7c5f4908bc..064ed3e1e3d468345238ee4359e48eccd912f193 100644 (file)
@@ -5229,7 +5229,7 @@ fuzzy_match_str_with_pos(char_u *str UNUSED, char_u *pat UNUSED)
  * - `*len` is set to the length of the matched word.
  * - `*score` contains the match score.
  *
- * If no match is found, `*ptr` is updated to to the end of the line.
+ * If no match is found, `*ptr` is updated to the end of the line.
  */
     int
 fuzzy_match_str_in_line(
@@ -5313,10 +5313,7 @@ search_for_fuzzy_match(
     pos_T      circly_end;
     int                found_new_match = FALSE;
     int                looped_around = FALSE;
-
-    int whole_line = ctrl_x_mode_whole_line();
-    if (whole_line)
-       current_pos.lnum += dir;
+    int                whole_line = ctrl_x_mode_whole_line();
 
     if (buf == curbuf)
         circly_end = *start_pos;
@@ -5327,6 +5324,9 @@ search_for_fuzzy_match(
         circly_end.coladd = 0;
     }
 
+    if (whole_line && start_pos->lnum != pos->lnum)
+       current_pos.lnum += dir;
+
     do {
 
        // Check if looped around and back to start position
@@ -5338,13 +5338,15 @@ search_for_fuzzy_match(
        {
            // Get the current line buffer
            *ptr = ml_get_buf(buf, current_pos.lnum, FALSE);
+           if (!whole_line)
+               *ptr += current_pos.col;
+
            // If ptr is end of line is reached, move to next line
            // or previous line based on direction
            if (*ptr != NULL && **ptr != NUL)
            {
                if (!whole_line)
                {
-                   *ptr += current_pos.col;
                    // Try to find a fuzzy match in the current line starting
                    // from current position
                    found_new_match = fuzzy_match_str_in_line(ptr, pattern,
@@ -5371,8 +5373,6 @@ search_for_fuzzy_match(
                                    else
                                       next_word_end = find_word_end(next_word_end);
                                }
-                               else if (looped_around)
-                                   found_new_match = FALSE;
 
                                *len = next_word_end - *ptr;
                                current_pos.col = *len;
index e63b13334a0d2739415c5633e8a3d6b37b2e0bd4..e2a69f3832b7b8dce57bfb1153edf94efe37b978 100644 (file)
@@ -2949,6 +2949,12 @@ func Test_complete_fuzzy_collect()
   call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!')
   call assert_equal('Tex', getline(line('.') - 1))
 
+  call setline(1, ['fuzzy', 'fuzzycollect', 'completefuzzycollect'])
+  call feedkeys("Gofuzzy\<C-X>\<C-N>\<C-N>\<C-N>\<CR>\<Esc>0", 'tx!')
+  call assert_equal('fuzzycollect', getline(line('.') - 1))
+  call feedkeys("Gofuzzy\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<CR>\<Esc>0", 'tx!')
+  call assert_equal('completefuzzycollect', getline(line('.') - 1))
+
   bw!
   bw!
   set completeopt& cfc& cpt&
index 474d2c7e115dc86a70fe35304a5ee0cbb828070c..65332f5e9a1503671165b2b400f50155e5f35e56 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1197,
 /**/
     1196,
 /**/