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>
diff --git a/src/popupmenu.c b/src/popupmenu.c
index 44235ef..443223d 100644
--- a/src/popupmenu.c
+++ b/src/popupmenu.c
@@ -410,7 +410,7 @@
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 @@
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 @@
}
}
}
- 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);