0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 9.1.0629: Rename of pum hl_group is incomplete

Problem:  Rename of pum hl_group is incomplete in source.
Solution: Also rename the test function.  Rename to user_hlattr in code
          to avoid confusion with pum_extra.  Add test with matched text
          highlighting (zeertzjq).

closes: #15348

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2024-07-27 13:21:49 +02:00
committed by Christian Brabandt
parent f08865ce83
commit 4100852e09
9 changed files with 89 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
*insert.txt* For Vim version 9.1. Last change: 2024 Jul 25 *insert.txt* For Vim version 9.1. Last change: 2024 Jul 27
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1183,12 +1183,12 @@ items:
user_data custom data which is associated with the item and user_data custom data which is associated with the item and
available in |v:completed_item|; it can be any type; available in |v:completed_item|; it can be any type;
defaults to an empty string defaults to an empty string
hl_group allows specifying an additional highlight group to hl_group an additional highlight group whose attributes are
apply extra attributes to completion items in the combined with |hl-PmenuSel| and |hl-Pmenu| or
popupmenu. Is combined with |hl-PmenuSel| and |hl-PmenuMatchSel| and |hl-PmenuMatch| highlight
|hl-Pmenu| highlighting attributes to apply cterm and attributes in the popup menu to apply cterm and gui
gui properties, such as strikethrough to the properties (with higher priority) like strikethrough
completion items. to the completion items
All of these except "icase", "equal", "dup" and "empty" must be a string. If All of these except "icase", "equal", "dup" and "empty" must be a string. If
an item does not meet these requirements then an error message is given and an item does not meet these requirements then an error message is given and

View File

@@ -359,7 +359,7 @@ cmdline_pum_create(
compl_match_array[i].pum_info = NULL; compl_match_array[i].pum_info = NULL;
compl_match_array[i].pum_extra = NULL; compl_match_array[i].pum_extra = NULL;
compl_match_array[i].pum_kind = NULL; compl_match_array[i].pum_kind = NULL;
compl_match_array[i].pum_extrahlattr = -1; compl_match_array[i].pum_user_hlattr = -1;
} }
// Compute the popup menu starting column // Compute the popup menu starting column

View File

@@ -114,7 +114,7 @@ struct compl_S
int cp_flags; // CP_ values int cp_flags; // CP_ values
int cp_number; // sequence number int cp_number; // sequence number
int cp_score; // fuzzy match score int cp_score; // fuzzy match score
int cp_extrahlattr; // extra highlight group attr int cp_user_hlattr; // highlight attribute to combine with
}; };
// values for cp_flags // values for cp_flags
@@ -206,7 +206,7 @@ static int compl_selected_item = -1;
static int *compl_fuzzy_scores; static int *compl_fuzzy_scores;
static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup, int extrahl); static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup, int user_hlattr);
static void ins_compl_longest_match(compl_T *match); static void ins_compl_longest_match(compl_T *match);
static void ins_compl_del_pum(void); static void ins_compl_del_pum(void);
static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir);
@@ -780,7 +780,7 @@ ins_compl_add(
int cdir, int cdir,
int flags_arg, int flags_arg,
int adup, // accept duplicate match int adup, // accept duplicate match
int extra_hlattr) int user_hlattr)
{ {
compl_T *match; compl_T *match;
int dir = (cdir == 0 ? compl_direction : cdir); int dir = (cdir == 0 ? compl_direction : cdir);
@@ -844,7 +844,7 @@ ins_compl_add(
else else
match->cp_fname = NULL; match->cp_fname = NULL;
match->cp_flags = flags; match->cp_flags = flags;
match->cp_extrahlattr = extra_hlattr; match->cp_user_hlattr = user_hlattr;
if (cptext != NULL) if (cptext != NULL)
{ {
@@ -1341,7 +1341,7 @@ ins_compl_build_pum(void)
compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND]; compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
compl_match_array[i].pum_info = compl->cp_text[CPT_INFO]; compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
compl_match_array[i].pum_score = compl->cp_score; compl_match_array[i].pum_score = compl->cp_score;
compl_match_array[i].pum_extrahlattr = compl->cp_extrahlattr; compl_match_array[i].pum_user_hlattr = compl->cp_user_hlattr;
if (compl->cp_text[CPT_MENU] != NULL) if (compl->cp_text[CPT_MENU] != NULL)
compl_match_array[i++].pum_extra = compl_match_array[i++].pum_extra =
compl->cp_text[CPT_MENU]; compl->cp_text[CPT_MENU];
@@ -2860,8 +2860,8 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
char_u *(cptext[CPT_COUNT]); char_u *(cptext[CPT_COUNT]);
typval_T user_data; typval_T user_data;
int status; int status;
char_u *extra_hlname; char_u *user_hlname;
int extra_hlattr = -1; int user_hlattr = -1;
user_data.v_type = VAR_UNKNOWN; user_data.v_type = VAR_UNKNOWN;
if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
@@ -2871,9 +2871,9 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
cptext[CPT_MENU] = dict_get_string(tv->vval.v_dict, "menu", FALSE); cptext[CPT_MENU] = dict_get_string(tv->vval.v_dict, "menu", FALSE);
cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE); cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE);
cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE); cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE);
extra_hlname = dict_get_string(tv->vval.v_dict, "hl_group", FALSE); user_hlname = dict_get_string(tv->vval.v_dict, "hl_group", FALSE);
if (extra_hlname != NULL && *extra_hlname != NUL) if (user_hlname != NULL && *user_hlname != NUL)
extra_hlattr = syn_name2attr(extra_hlname); user_hlattr = syn_name2attr(user_hlname);
dict_get_tv(tv->vval.v_dict, "user_data", &user_data); dict_get_tv(tv->vval.v_dict, "user_data", &user_data);
if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL
@@ -2898,7 +2898,7 @@ ins_compl_add_tv(typval_T *tv, int dir, int fast)
return FAIL; return FAIL;
} }
status = ins_compl_add(word, -1, NULL, cptext, status = ins_compl_add(word, -1, NULL, cptext,
&user_data, dir, flags, dup, extra_hlattr); &user_data, dir, flags, dup, user_hlattr);
if (status != OK) if (status != OK)
clear_tv(&user_data); clear_tv(&user_data);
return status; return status;

View File

@@ -425,7 +425,7 @@ pum_under_menu(int row, int col, int only_redrawing)
* Returns attributes for every cell, or NULL if all attributes are the same. * Returns attributes for every cell, or NULL if all attributes are the same.
*/ */
static int * static int *
pum_compute_text_attrs(char_u *text, hlf_T hlf, int extra_hlattr) pum_compute_text_attrs(char_u *text, hlf_T hlf, int user_hlattr)
{ {
int i; int i;
size_t leader_len; size_t leader_len;
@@ -483,8 +483,8 @@ pum_compute_text_attrs(char_u *text, hlf_T hlf, int extra_hlattr)
else if (matched_start && ptr < text + leader_len) else if (matched_start && ptr < text + leader_len)
new_attr = highlight_attr[hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI]; new_attr = highlight_attr[hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI];
if (extra_hlattr > 0) if (user_hlattr > 0)
new_attr = hl_combine_attr(new_attr, extra_hlattr); new_attr = hl_combine_attr(new_attr, user_hlattr);
char_cells = mb_ptr2cells(ptr); char_cells = mb_ptr2cells(ptr);
for (i = 0; i < char_cells; i++) for (i = 0; i < char_cells; i++)
@@ -631,8 +631,8 @@ pum_redraw(void)
{ {
hlf = hlfs[round]; hlf = hlfs[round];
attr = highlight_attr[hlf]; attr = highlight_attr[hlf];
if (pum_array[idx].pum_extrahlattr > 0) if (pum_array[idx].pum_user_hlattr > 0)
attr = hl_combine_attr(attr, pum_array[idx].pum_extrahlattr); attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr);
width = 0; width = 0;
s = NULL; s = NULL;
switch (round) switch (round)
@@ -661,8 +661,8 @@ pum_redraw(void)
if (saved != NUL) if (saved != NUL)
*p = saved; *p = saved;
int extra_hlattr = pum_array[idx].pum_extrahlattr; int user_hlattr = pum_array[idx].pum_user_hlattr;
attrs = pum_compute_text_attrs(st, hlf, extra_hlattr); attrs = pum_compute_text_attrs(st, hlf, user_hlattr);
#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
if (pum_rl) if (pum_rl)

View File

@@ -4472,7 +4472,7 @@ typedef struct
char_u *pum_info; // extra info char_u *pum_info; // extra info
int pum_score; // fuzzy match score int pum_score; // fuzzy match score
int pum_idx; // index of item before sorting by score int pum_idx; // index of item before sorting by score
int pum_extrahlattr; // extra highlight group attr for combine int pum_user_hlattr; // highlight attribute to combine with
} pumitem_T; } pumitem_T;
/* /*

View File

@@ -0,0 +1,20 @@
|a+0&#ffffff0|w|o|r|d|1> @68
|a+8#ff404010#e0e0e08|w|o+0&&|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
|a+8#0000e05#ffd7ff255|w|o+0#0000001&|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52
|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@26

View File

@@ -0,0 +1,20 @@
|a+0&#ffffff0|w|o|r|d|2> @68
|a+8#ff404010#ffd7ff255|w|o+0&&|r|d|1| |W| |e|x|t|r|a| |t|e|x|t| |1| | +0#4040ff13#ffffff0@52
|a+8#00e0e07#e0e0e08|w|o+0#0000001&|r|d|2| |W| |e|x|t|r|a| |t|e|x|t| |2| | +0#4040ff13#ffffff0@52
|你*0#ff404010#ffd7ff255|好| +&@2|W| |e|x|t|r|a| |t|e|x|t| |3| | +0#4040ff13#ffffff0@52
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |U|s|e|r| |d|e|f|i|n|e|d| |c|o|m|p|l|e|t|i|o|n| |(|^|U|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |2| |o|f| |3| +0#0000000&@26

View File

@@ -1499,10 +1499,9 @@ func Test_pum_highlights_match()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc
func Test_pum_extrahl() func Test_pum_user_hl_group()
CheckScreendump CheckScreendump
let lines =<< trim END let lines =<< trim END
hi StrikeFake ctermfg=9
func CompleteFunc( findstart, base ) func CompleteFunc( findstart, base )
if a:findstart if a:findstart
return 0 return 0
@@ -1516,15 +1515,31 @@ func Test_pum_extrahl()
endfunc endfunc
set completeopt=menu set completeopt=menu
set completefunc=CompleteFunc set completefunc=CompleteFunc
hi StrikeFake ctermfg=9
func HlMatch()
hi PmenuMatchSel ctermfg=6 ctermbg=7 cterm=underline
hi PmenuMatch ctermfg=4 ctermbg=225 cterm=underline
endfunc
END END
call writefile(lines, 'Xscript', 'D') call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {}) let buf = RunVimInTerminal('-S Xscript', {})
call TermWait(buf) call TermWait(buf)
call term_sendkeys(buf, "iaw\<C-X>\<C-u>") call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
call TermWait(buf, 50)
call VerifyScreenDump(buf, 'Test_pum_highlights_12', {}) call VerifyScreenDump(buf, 'Test_pum_highlights_12', {})
call term_sendkeys(buf, "\<C-E>\<Esc>u") call term_sendkeys(buf, "\<C-E>\<Esc>")
call TermWait(buf) call TermWait(buf)
call term_sendkeys(buf, ":call HlMatch()\<CR>")
call TermWait(buf)
call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
call VerifyScreenDump(buf, 'Test_pum_highlights_13', {})
call term_sendkeys(buf, "\<C-N>")
call VerifyScreenDump(buf, 'Test_pum_highlights_14', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc

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 */
/**/
629,
/**/ /**/
628, 628,
/**/ /**/