Commit: patch 9.1.1269: completion: compl_shown_match is updated when starting keyword completion

0 views
Skip to first unread message

Christian Brabandt

unread,
Apr 2, 2025, 2:30:14 PM4/2/25
to vim...@googlegroups.com
patch 9.1.1269: completion: compl_shown_match is updated when starting keyword completion

Commit: https://github.com/vim/vim/commit/e4e4d1c381e9d0af55f6111e9bcaf98ad60461fc
Author: glepnir <gleph...@gmail.com>
Date: Wed Apr 2 20:18:25 2025 +0200

patch 9.1.1269: completion: compl_shown_match is updated when starting keyword completion

Problem: compl_shown_match is updated when starting keyword completion
and does not include fuzzy matching.
Solution: Do not update compl_shown_match when starting keyword
completion, since it is the one already selected by the
keyword completion direction. (glepnir)

closes: #17033

Signed-off-by: glepnir <gleph...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/insexpand.c b/src/insexpand.c
index 3c81749c6..de3d51982 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -1352,10 +1352,10 @@ ins_compl_build_pum(void)
int compl_no_select = (cur_cot_flags & COT_NOSELECT) != 0;
int fuzzy_filter = (cur_cot_flags & COT_FUZZY) != 0;
int fuzzy_sort = fuzzy_filter && !(cur_cot_flags & COT_NOSORT);
-
compl_T *match_head = NULL;
compl_T *match_tail = NULL;
compl_T *match_next = NULL;
+ int update_shown_match = fuzzy_filter;

// Need to build the popup menu list.
compl_match_arraysize = 0;
@@ -1366,6 +1366,10 @@ ins_compl_build_pum(void)
if (match_at_original_text(compl_shown_match))
shown_match_ok = TRUE;

+ if (fuzzy_filter && ctrl_x_mode_normal() && compl_leader.string == NULL
+ && compl_shown_match->cp_score > 0)
+ update_shown_match = FALSE;
+
if (compl_leader.string != NULL
&& STRCMP(compl_leader.string, compl_orig_text.string) == 0
&& shown_match_ok == FALSE)
@@ -1415,7 +1419,8 @@ ins_compl_build_pum(void)
shown_compl = compl;
// Update the maximum fuzzy score and the shown match
// if the current item's score is higher
- if (fuzzy_sort && compl->cp_score > max_fuzzy_score)
+ if (fuzzy_sort && compl->cp_score > max_fuzzy_score
+ && update_shown_match)
{
did_find_shown_match = TRUE;
max_fuzzy_score = compl->cp_score;
diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim
index 50b183469..f60aba8d7 100644
--- a/src/testdir/test_ins_complete.vim
+++ b/src/testdir/test_ins_complete.vim
@@ -2829,6 +2829,12 @@ func Test_complete_opt_fuzzy()
call feedkeys("i\<C-R>=CompAnother()\<CR>\<C-P>\<C-P>", 'tx')
call assert_equal("for", g:abbr)

+ set cot=menu,fuzzy
+ call feedkeys("Sblue\<CR>bar\<CR>b\<C-X>\<C-P>\<C-Y>\<ESC>", 'tx')
+ call assert_equal('bar', getline('.'))
+ call feedkeys("Sb\<C-X>\<C-N>\<C-Y>\<ESC>", 'tx')
+ call assert_equal('blue', getline('.'))
+
" clean up
set omnifunc=
bw!
diff --git a/src/version.c b/src/version.c
index 192fd0f15..7882f5eb7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1269,
/**/
1268,
/**/
Reply all
Reply to author
Forward
0 new messages