]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0733: keyword completion does not work with fuzzy v9.1.0733
authorglepnir <glephunter@gmail.com>
Sun, 15 Sep 2024 18:06:28 +0000 (20:06 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 15 Sep 2024 18:09:42 +0000 (20:09 +0200)
Problem:  keyword completion does not work with fuzzy
          (egesip)
Solution: handle ctrl_x_mode_normal() specifically
          (glepnir)

fixes: #15412
closes: #15424

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

index d424fff0071a6048c0e49ace6d82c8a82fe1d67f..63bf0700db78f4a54566330ddbe79ff8816cbae8 100644 (file)
@@ -5198,6 +5198,7 @@ ins_compl_start(void)
     if (line_invalid)
        line = ml_get(curwin->w_cursor.lnum);
 
+    int in_fuzzy = get_cot_flags() & COT_FUZZY;
     if (compl_status_adding())
     {
        edit_submode_pre = (char_u *)_(" Adding");
@@ -5214,6 +5215,11 @@ ins_compl_start(void)
            compl_length = 0;
            compl_col = curwin->w_cursor.col;
        }
+       else if (ctrl_x_mode_normal() && in_fuzzy)
+       {
+           compl_startpos = curwin->w_cursor;
+           compl_cont_status &= CONT_S_IPOS;
+       }
     }
     else
     {
index a7fd44e680369b7e10e1cd584a46d52b8ac4e476..661bcc7a59c3116e371e527408e9bb60231e47af 100644 (file)
@@ -5219,6 +5219,8 @@ search_for_fuzzy_match(
     pos_T      circly_end;
     int                found_new_match = FALSE;
     int                looped_around = FALSE;
+    char_u     *next_word_end = NULL;
+    char_u     *match_word = NULL;
 
     if (whole_line)
        current_pos.lnum += dir;
@@ -5254,6 +5256,35 @@ search_for_fuzzy_match(
                    found_new_match = fuzzy_match_str_in_line(ptr, pattern, len, &current_pos);
                    if (found_new_match)
                    {
+                       if (ctrl_x_mode_normal())
+                       {
+                           match_word = vim_strnsave(*ptr, *len);
+                           if (STRCMP(match_word, pattern) == 0)
+                           {
+                               next_word_end = find_word_start(*ptr + *len);
+                               if (*next_word_end != NUL && *next_word_end != NL)
+                               {
+                                   // Find end of the word.
+                                   if (has_mbyte)
+                                       while (*next_word_end != NUL)
+                                       {
+                                           int l = (*mb_ptr2len)(next_word_end);
+
+                                           if (l < 2 && !vim_iswordc(*next_word_end))
+                                               break;
+                                           next_word_end += l;
+                                       }
+                                   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;
+                           }
+                           vim_free(match_word);
+                       }
                        *pos = current_pos;
                        break;
                    }
index aee33936f642ee3da454e4bad17db86e05c7ce67..df254847ee5093f80d33415c7981e05489f25cc3 100644 (file)
@@ -2654,10 +2654,38 @@ func Test_complete_fuzzy_match()
   call feedkeys("Su\<C-X>\<C-L>\<C-P>\<Esc>0", 'tx!')
   call assert_equal('no one can save me but you', getline('.'))
 
+  " issue #15412
+  call setline(1, ['alpha bravio charlie'])
+  call feedkeys("Salpha\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha bravio', getline('.'))
+  call feedkeys("Salp\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha', getline('.'))
+  call feedkeys("A\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha bravio', getline('.'))
+  call feedkeys("A\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha bravio charlie', getline('.'))
+
+  set complete-=i
+  call feedkeys("Salp\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha', getline('.'))
+  call feedkeys("A\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha bravio', getline('.'))
+  call feedkeys("A\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha bravio charlie', getline('.'))
+
+  call setline(1, ['alpha bravio charlie', 'alpha another'])
+  call feedkeys("Salpha\<C-X>\<C-N>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('alpha another', getline('.'))
+  call setline(1, ['你好 我好', '你好 他好'])
+  call feedkeys("S你好\<C-X>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('你好 我好', getline('.'))
+  call feedkeys("S你好\<C-X>\<C-N>\<C-N>\<Esc>0", 'tx!')
+  call assert_equal('你好 他好', getline('.'))
+
   " issue #15526
   set completeopt=fuzzy,menuone,menu,noselect
   call setline(1, ['Text', 'ToText', ''])
-  call cursor(2, 1)
+  call cursor(3, 1)
   call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!')
   call assert_equal('Tex', getline('.'))
 
index 6138f51521a2cce9b8877945c0c9fe2ccc49d8db..f5bd1433cccd8e852f99ddfb074b1a5f168a8a22 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    733,
 /**/
     732,
 /**/