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
@@ -1183,12 +1183,12 @@ items:
user_data custom data which is associated with the item and
available in |v:completed_item|; it can be any type;
defaults to an empty string
hl_group allows specifying an additional highlight group to
apply extra attributes to completion items in the
popupmenu. Is combined with |hl-PmenuSel| and
|hl-Pmenu| highlighting attributes to apply cterm and
gui properties, such as strikethrough to the
completion items.
hl_group an additional highlight group whose attributes are
combined with |hl-PmenuSel| and |hl-Pmenu| or
|hl-PmenuMatchSel| and |hl-PmenuMatch| highlight
attributes in the popup menu to apply cterm and gui
properties (with higher priority) like strikethrough
to the completion items
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

View File

@@ -359,7 +359,7 @@ cmdline_pum_create(
compl_match_array[i].pum_info = NULL;
compl_match_array[i].pum_extra = 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

View File

@@ -114,7 +114,7 @@ struct compl_S
int cp_flags; // CP_ values
int cp_number; // sequence number
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
@@ -206,7 +206,7 @@ static int compl_selected_item = -1;
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_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);
@@ -780,7 +780,7 @@ ins_compl_add(
int cdir,
int flags_arg,
int adup, // accept duplicate match
int extra_hlattr)
int user_hlattr)
{
compl_T *match;
int dir = (cdir == 0 ? compl_direction : cdir);
@@ -844,7 +844,7 @@ ins_compl_add(
else
match->cp_fname = NULL;
match->cp_flags = flags;
match->cp_extrahlattr = extra_hlattr;
match->cp_user_hlattr = user_hlattr;
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_info = compl->cp_text[CPT_INFO];
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)
compl_match_array[i++].pum_extra =
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]);
typval_T user_data;
int status;
char_u *extra_hlname;
int extra_hlattr = -1;
char_u *user_hlname;
int user_hlattr = -1;
user_data.v_type = VAR_UNKNOWN;
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_KIND] = dict_get_string(tv->vval.v_dict, "kind", 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);
if (extra_hlname != NULL && *extra_hlname != NUL)
extra_hlattr = syn_name2attr(extra_hlname);
user_hlname = dict_get_string(tv->vval.v_dict, "hl_group", FALSE);
if (user_hlname != NULL && *user_hlname != NUL)
user_hlattr = syn_name2attr(user_hlname);
dict_get_tv(tv->vval.v_dict, "user_data", &user_data);
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;
}
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)
clear_tv(&user_data);
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.
*/
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;
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)
new_attr = highlight_attr[hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI];
if (extra_hlattr > 0)
new_attr = hl_combine_attr(new_attr, extra_hlattr);
if (user_hlattr > 0)
new_attr = hl_combine_attr(new_attr, user_hlattr);
char_cells = mb_ptr2cells(ptr);
for (i = 0; i < char_cells; i++)
@@ -631,8 +631,8 @@ pum_redraw(void)
{
hlf = hlfs[round];
attr = highlight_attr[hlf];
if (pum_array[idx].pum_extrahlattr > 0)
attr = hl_combine_attr(attr, pum_array[idx].pum_extrahlattr);
if (pum_array[idx].pum_user_hlattr > 0)
attr = hl_combine_attr(attr, pum_array[idx].pum_user_hlattr);
width = 0;
s = NULL;
switch (round)
@@ -661,8 +661,8 @@ pum_redraw(void)
if (saved != NUL)
*p = saved;
int extra_hlattr = pum_array[idx].pum_extrahlattr;
attrs = pum_compute_text_attrs(st, hlf, extra_hlattr);
int user_hlattr = pum_array[idx].pum_user_hlattr;
attrs = pum_compute_text_attrs(st, hlf, user_hlattr);
#ifdef FEAT_RIGHTLEFT
if (pum_rl)

View File

@@ -4472,7 +4472,7 @@ typedef struct
char_u *pum_info; // extra info
int pum_score; // fuzzy match 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;
/*

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)
endfunc
func Test_pum_extrahl()
func Test_pum_user_hl_group()
CheckScreendump
let lines =<< trim END
hi StrikeFake ctermfg=9
func CompleteFunc( findstart, base )
if a:findstart
return 0
@@ -1516,15 +1515,31 @@ func Test_pum_extrahl()
endfunc
set completeopt=menu
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
call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {})
call TermWait(buf)
call term_sendkeys(buf, "iaw\<C-X>\<C-u>")
call TermWait(buf, 50)
call term_sendkeys(buf, "Saw\<C-X>\<C-U>")
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 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)
endfunc

View File

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