From fbe546e25d21f3184814d696c329d23d146bd615 Mon Sep 17 00:00:00 2001 From: glepnir Date: Sat, 11 Jan 2025 07:58:45 +0800 Subject: vim-patch:9.1.0996: ComplMatchIns may highlight wrong text (#31931) Problem: ComplMatchIns may highlight wrong text Solution: don't highlight in case of fuzzy match, skip-highlight when not inserting anything (glepnir) closes: vim/vim#16404 https://github.com/vim/vim/commit/e890887b8052561ac5f8dce218e578ed28599cc6 --- src/nvim/insexpand.c | 6 +++++- test/functional/ui/popupmenu_spec.lua | 33 +++++++++++++++++++++++++++++++++ test/old/testdir/test_popup.vim | 14 ++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 419c806592..d1559b00f1 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -966,7 +966,11 @@ static void ins_compl_insert_bytes(char *p, int len) /// -1 mean normal item. int ins_compl_col_range_attr(int col) { - if (col >= compl_col && col < compl_ins_end_col) { + if (get_cot_flags() & kOptCotFlagFuzzy) { + return -1; + } + + if (col >= (compl_col + (int)compl_leader.size) && col < compl_ins_end_col) { return syn_name2attr("ComplMatchIns"); } diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 60d59190ce..66b62341a9 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -5853,6 +5853,39 @@ describe('builtin popupmenu', function() {2:-- INSERT --} | ]]) feed('') + + -- Does not highlight the compl leader + command('set cot+=menuone,noselect') + feed('S') + local pum_start = [[ + {10:^ }| + {n:foo }{1: }| + {n:bar }{1: }| + {n:你好 }{1: }| + {1:~ }|*15 + {2:-- }{8:Back at original} | + ]] + screen:expect(pum_start) + feed('f') + screen:expect([[ + {10:f}{9:oo}{10:^ }| + {s:foo }{1: }| + {1:~ }|*17 + {2:-- }{5:match 1 of 3} | + ]]) + feed('') + + command('set cot+=fuzzy') + feed('S') + screen:expect(pum_start) + feed('f') + screen:expect([[ + {10:foo^ }| + {s:foo }{1: }| + {1:~ }|*17 + {2:-- }{5:match 1 of 3} | + ]]) + feed('') end) end end diff --git a/test/old/testdir/test_popup.vim b/test/old/testdir/test_popup.vim index e902ea3bc2..7f570182e4 100644 --- a/test/old/testdir/test_popup.vim +++ b/test/old/testdir/test_popup.vim @@ -1817,6 +1817,20 @@ func Test_pum_matchins_highlight_combine() call VerifyScreenDump(buf, 'Test_pum_matchins_combine_06', {}) call term_sendkeys(buf, "\") + " Does not highlight the compl leader + call TermWait(buf) + call term_sendkeys(buf, ":set cot+=menuone,noselect\") + call TermWait(buf) + call term_sendkeys(buf, "S\\f\") + call VerifyScreenDump(buf, 'Test_pum_matchins_combine_07', {}) + call term_sendkeys(buf, "\\") + + call term_sendkeys(buf, ":set cot+=fuzzy\") + call TermWait(buf) + call term_sendkeys(buf, "S\\f\") + call VerifyScreenDump(buf, 'Test_pum_matchins_combine_08', {}) + call term_sendkeys(buf, "\\") + call StopVimInTerminal(buf) endfunc -- cgit