0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.1.0485: Matched text shouldn't be highlighted in "kind" and "menu"

Problem:  Matched text shouldn't be highlighted in "kind" and "menu".
Solution: Pass hlf_T instead of the attribute.  Fix indent.
          (zeertzjq)

closes: #14996

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2024-06-14 20:24:22 +02:00 committed by Christian Brabandt
parent c509c009bb
commit afbe5359e9
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
6 changed files with 80 additions and 76 deletions

View File

@ -420,7 +420,7 @@ pum_under_menu(int row, int col, int only_redrawing)
* displays text on the popup menu with specific attributes. * displays text on the popup menu with specific attributes.
*/ */
static void static void
pum_screen_put_with_attr(int row, int col, char_u *text, int textlen, int attr) pum_screen_put_with_attr(int row, int col, char_u *text, int textlen, hlf_T hlf)
{ {
int i; int i;
int leader_len; int leader_len;
@ -434,69 +434,68 @@ pum_screen_put_with_attr(int row, int col, char_u *text, int textlen, int attr)
char_u *leader = ins_compl_leader(); char_u *leader = ins_compl_leader();
int in_fuzzy = (get_cot_flags() & COT_FUZZY) != 0; int in_fuzzy = (get_cot_flags() & COT_FUZZY) != 0;
if (leader == NULL || *leader == NUL || if (leader == NULL || *leader == NUL || (hlf != HLF_PSI && hlf != HLF_PNI)
(highlight_attr[HLF_PMSI] == highlight_attr[HLF_PSI] && || (highlight_attr[HLF_PMSI] == highlight_attr[HLF_PSI]
highlight_attr[HLF_PMNI] == highlight_attr[HLF_PNI])) && highlight_attr[HLF_PMNI] == highlight_attr[HLF_PNI]))
{ {
screen_puts_len(text, textlen, row, col, attr); screen_puts_len(text, textlen, row, col, highlight_attr[hlf]);
return; return;
} }
#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
if (curwin->w_p_rl) if (curwin->w_p_rl)
rt_leader = reverse_text(leader); rt_leader = reverse_text(leader);
#endif #endif
match_leader = rt_leader != NULL ? rt_leader : leader; match_leader = rt_leader != NULL ? rt_leader : leader;
leader_len = (int)STRLEN(match_leader); leader_len = (int)STRLEN(match_leader);
if (in_fuzzy) if (in_fuzzy)
ga = fuzzy_match_str_with_pos(text, match_leader); ga = fuzzy_match_str_with_pos(text, match_leader);
// Render text with proper attributes // Render text with proper attributes
while (*ptr != NUL && ptr < text + textlen) while (*ptr != NUL && ptr < text + textlen)
{ {
char_len = mb_ptr2len(ptr); char_len = mb_ptr2len(ptr);
cells = mb_ptr2cells(ptr); cells = mb_ptr2cells(ptr);
new_attr = attr; new_attr = highlight_attr[hlf];
if (ga != NULL) if (ga != NULL)
{ {
// Handle fuzzy matching // Handle fuzzy matching
for (i = 0; i < ga->ga_len; i++) for (i = 0; i < ga->ga_len; i++)
{ {
int_u *match_pos = ((int_u *)ga->ga_data) + i; int_u *match_pos = ((int_u *)ga->ga_data) + i;
int_u actual_char_pos = 0; int_u actual_char_pos = 0;
char_u *temp_ptr = text; char_u *temp_ptr = text;
while (temp_ptr < ptr) while (temp_ptr < ptr)
{ {
temp_ptr += mb_ptr2len(temp_ptr); temp_ptr += mb_ptr2len(temp_ptr);
actual_char_pos++; actual_char_pos++;
} }
if (actual_char_pos == match_pos[0]) if (actual_char_pos == match_pos[0])
{ {
new_attr = highlight_attr[(attr == highlight_attr[HLF_PSI] new_attr = highlight_attr[hlf == HLF_PSI
? HLF_PMSI : HLF_PMNI)]; ? HLF_PMSI : HLF_PMNI];
break; break;
} }
} }
} }
else if (!in_fuzzy && (ptr - text < leader_len) && else if (!in_fuzzy && (ptr - text < leader_len)
(STRNCMP(text, match_leader, leader_len) == 0)) && (STRNCMP(text, match_leader, leader_len) == 0))
new_attr = highlight_attr[(attr == highlight_attr[HLF_PSI] new_attr = highlight_attr[hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI];
? HLF_PMSI : HLF_PMNI)];
screen_puts_len(ptr, char_len, row, col, new_attr); screen_puts_len(ptr, char_len, row, col, new_attr);
col += cells; col += cells;
ptr += char_len; ptr += char_len;
} }
if (ga != NULL) if (ga != NULL)
{ {
ga_clear(ga); ga_clear(ga);
vim_free(ga); vim_free(ga);
} }
if (rt_leader) if (rt_leader)
vim_free(rt_leader); vim_free(rt_leader);
} }
/* /*
@ -509,8 +508,9 @@ pum_redraw(void)
int col; int col;
int attr_scroll = highlight_attr[HLF_PSB]; int attr_scroll = highlight_attr[HLF_PSB];
int attr_thumb = highlight_attr[HLF_PST]; int attr_thumb = highlight_attr[HLF_PST];
hlf_T *hlfs; // array used for highlights
hlf_T hlf;
int attr; int attr;
int *attrs; // array used for highlights
int i; int i;
int idx; int idx;
char_u *s; char_u *s;
@ -521,17 +521,17 @@ pum_redraw(void)
int round; int round;
int n; int n;
int attrsNorm[3]; hlf_T hlfsNorm[3];
int attrsSel[3]; hlf_T hlfsSel[3];
// "word" // "word"
attrsNorm[0] = highlight_attr[HLF_PNI]; hlfsNorm[0] = HLF_PNI;
attrsSel[0] = highlight_attr[HLF_PSI]; hlfsSel[0] = HLF_PSI;
// "kind" // "kind"
attrsNorm[1] = highlight_attr[HLF_PNK]; hlfsNorm[1] = HLF_PNK;
attrsSel[1] = highlight_attr[HLF_PSK]; hlfsSel[1] = HLF_PSK;
// "extra text" // "extra text"
attrsNorm[2] = highlight_attr[HLF_PNX]; hlfsNorm[2] = HLF_PNX;
attrsSel[2] = highlight_attr[HLF_PSX]; hlfsSel[2] = HLF_PSX;
if (call_update_screen) if (call_update_screen)
{ {
@ -566,8 +566,9 @@ pum_redraw(void)
for (i = 0; i < pum_height; ++i) for (i = 0; i < pum_height; ++i)
{ {
idx = i + pum_first; idx = i + pum_first;
attrs = (idx == pum_selected) ? attrsSel : attrsNorm; hlfs = (idx == pum_selected) ? hlfsSel : hlfsNorm;
attr = attrs[0]; // start with "word" highlight hlf = hlfs[0]; // start with "word" highlight
attr = highlight_attr[hlf];
// prepend a space if there is room // prepend a space if there is room
#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
@ -590,7 +591,8 @@ pum_redraw(void)
totwidth = 0; totwidth = 0;
for (round = 0; round < 3; ++round) for (round = 0; round < 3; ++round)
{ {
attr = attrs[round]; hlf = hlfs[round];
attr = highlight_attr[hlf];
width = 0; width = 0;
s = NULL; s = NULL;
switch (round) switch (round)
@ -650,7 +652,7 @@ pum_redraw(void)
size++; size++;
} }
} }
pum_screen_put_with_attr(row, col -size + 1, rt, (int)STRLEN(rt), attr); pum_screen_put_with_attr(row, col - size + 1, rt, (int)STRLEN(rt), hlf);
vim_free(rt_start); vim_free(rt_start);
} }
vim_free(st); vim_free(st);
@ -678,7 +680,7 @@ pum_redraw(void)
else else
--cells; --cells;
} }
pum_screen_put_with_attr(row, col, st, size, attr); pum_screen_put_with_attr(row, col, st, size, hlf);
vim_free(st); vim_free(st);
} }
col += width; col += width;

View File

@ -1,8 +1,8 @@
|f+0&#ffffff0|o> @72 |f+0&#ffffff0|o> @72
|f+0#00e0e07#ffd7ff255|o|o+0#0000001#e0e0e08| @11| +0#4040ff13#ffffff0@59 |f+0#00e0e07#ffd7ff255|o|o+0#0000001#e0e0e08| @4|f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|r| @8| +0#4040ff13#ffffff0@59 |f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|r| @1|f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|f+0#0000e05#ffd7ff255|o|o+0#0000001&|B|a|z| @8| +0#4040ff13#ffffff0@59 |f+0#0000e05#ffd7ff255|o|o+0#0000001&|B|a|z| @1|f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|l|a| @7| +0#4040ff13#ffffff0@59 |f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|l|a| |f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|~| @73 |~| @73
|~| @73 |~| @73
|~| @73 |~| @73

View File

@ -1,8 +1,8 @@
| +0&#ffffff0@70|o>f|o|f | +0&#ffffff0@70|o>f|o|f
| +0#4040ff13&@59| +0#0000001#e0e0e08@11|o|o+0#00e0e07#ffd7ff255|f | +0#4040ff13&@58| +0#0000001#e0e0e08@1|d|n|i|k|o@1|f| @3|o|o+0#00e0e07#ffd7ff255|f
| +0#4040ff13#ffffff0@59| +0#0000001#ffd7ff255@8|r|a|b|o|o+0#0000e05&|f | +0#4040ff13#ffffff0@58| +0#0000001#ffd7ff255@1|d|n|i|k|o@1|f| |r|a|b|o|o+0#0000e05&|f
| +0#4040ff13#ffffff0@59| +0#0000001#ffd7ff255@8|z|a|B|o|o+0#0000e05&|f | +0#4040ff13#ffffff0@58| +0#0000001#ffd7ff255@1|d|n|i|k|o@1|f| |z|a|B|o|o+0#0000e05&|f
| +0#4040ff13#ffffff0@59| +0#0000001#ffd7ff255@7|a|l|a|b|o|o+0#0000e05&|f | +0#4040ff13#ffffff0@58| +0#0000001#ffd7ff255@1|d|n|i|k|o@1|f|a|l|a|b|o|o+0#0000e05&|f
| +0#4040ff13#ffffff0@73|~ | +0#4040ff13#ffffff0@73|~
| @73|~ | @73|~
| @73|~ | @73|~

View File

@ -1,8 +1,8 @@
|f+0&#ffffff0|o> @72 |f+0&#ffffff0|o> @72
|f+0#00e0e07#ffd7ff255|o|o+0#0000001#e0e0e08| @11| +0#4040ff13#ffffff0@59 |f+0#00e0e07#ffd7ff255|o|o+0#0000001#e0e0e08| @4|f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|r| @8| +0#4040ff13#ffffff0@59 |f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|r| @1|f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|f+0#0000e05#ffd7ff255|o|o+0#0000001&|B|a|z| @8| +0#4040ff13#ffffff0@59 |f+0#0000e05#ffd7ff255|o|o+0#0000001&|B|a|z| @1|f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|l|a| @7| +0#4040ff13#ffffff0@59 |f+0#0000e05#ffd7ff255|o|o+0#0000001&|b|a|l|a| |f|o@1|k|i|n|d| | +0#4040ff13#ffffff0@58
|~| @73 |~| @73
|~| @73 |~| @73
|~| @73 |~| @73

View File

@ -1351,14 +1351,14 @@ func Test_pum_highlights_match()
endif endif
return { return {
\ 'words': [ \ 'words': [
\ { 'word': 'foo',}, \ { 'word': 'foo', 'kind': 'fookind' },
\ { 'word': 'foobar',}, \ { 'word': 'foobar', 'kind': 'fookind' },
\ { 'word': 'fooBaz',}, \ { 'word': 'fooBaz', 'kind': 'fookind' },
\ { 'word': 'foobala',}, \ { 'word': 'foobala', 'kind': 'fookind' },
\ { 'word': '你好',}, \ { 'word': '你好' },
\ { 'word': '你好吗',}, \ { 'word': '你好吗' },
\ { 'word': '你不好吗',}, \ { 'word': '你不好吗' },
\ { 'word': '你可好吗',}, \ { 'word': '你可好吗' },
\]} \]}
endfunc endfunc
set omnifunc=Omni_test set omnifunc=Omni_test

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
485,
/**/ /**/
484, 484,
/**/ /**/