mirror of
https://github.com/vim/vim.git
synced 2025-11-10 10:47:23 -05:00
patch 9.1.1170: wildmenu highlighting in popup can be improved
Problem: wildmenu highlighting in popup can be improved
Solution: Check if the completion items contain submatches of the
entered text (Girish Palya).
This update enables highlighting in the popup menu even when the matched
fragment or pattern appears within an item (string) rather than only at the
beginning. This is especially useful for custom completion, where menu items
may not always start with the typed pattern.
For specific use cases, refer to the two examples in
https://github.com/vim/vim/pull/16759
A sliding window approach is used with direct string comparison. Performance
is not a concern, as highlighting is applied only to displayed lines, even if
the menu list is arbitrarily long.
closes: #16785
Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
29d596c80a
commit
4ec46f3210
@@ -410,7 +410,7 @@ pum_compute_text_attrs(char_u *text, hlf_T hlf, int user_hlattr)
|
||||
int *attrs = NULL;
|
||||
char_u *leader = NULL;
|
||||
int in_fuzzy;
|
||||
int matched_start = FALSE;
|
||||
int matched_len = -1;
|
||||
int_u char_pos = 0;
|
||||
int is_select = FALSE;
|
||||
|
||||
@@ -435,8 +435,6 @@ pum_compute_text_attrs(char_u *text, hlf_T hlf, int user_hlattr)
|
||||
|
||||
if (in_fuzzy)
|
||||
ga = fuzzy_match_str_with_pos(text, leader);
|
||||
else
|
||||
matched_start = MB_STRNICMP(text, leader, leader_len) == 0;
|
||||
|
||||
while (*ptr != NUL)
|
||||
{
|
||||
@@ -455,10 +453,16 @@ pum_compute_text_attrs(char_u *text, hlf_T hlf, int user_hlattr)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (matched_start && ptr < text + leader_len)
|
||||
else
|
||||
{
|
||||
new_attr = highlight_attr[is_select ? HLF_PMSI : HLF_PMNI];
|
||||
new_attr = hl_combine_attr(highlight_attr[hlf], new_attr);
|
||||
if (matched_len < 0 && MB_STRNICMP(ptr, leader, leader_len) == 0)
|
||||
matched_len = leader_len;
|
||||
if (matched_len > 0)
|
||||
{
|
||||
new_attr = highlight_attr[is_select ? HLF_PMSI : HLF_PMNI];
|
||||
new_attr = hl_combine_attr(highlight_attr[hlf], new_attr);
|
||||
matched_len--;
|
||||
}
|
||||
}
|
||||
|
||||
new_attr = hl_combine_attr(highlight_attr[HLF_PNI], new_attr);
|
||||
|
||||
Reference in New Issue
Block a user