]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0629: Rename of pum hl_group is incomplete v9.1.0629
authorzeertzjq <zeertzjq@outlook.com>
Sat, 27 Jul 2024 11:21:49 +0000 (13:21 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 27 Jul 2024 11:21:49 +0000 (13:21 +0200)
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>
runtime/doc/insert.txt
src/cmdexpand.c
src/insexpand.c
src/popupmenu.c
src/structs.h
src/testdir/dumps/Test_pum_highlights_13.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_highlights_14.dump [new file with mode: 0644]
src/testdir/test_popup.vim
src/version.c

index e85f341c8fac5519f78532379fc38a1d9b6fe3b3..e80fea8c2bb6362b6e64d58a62695076644c977a 100644 (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
index a33d6bede138e4c31e384fc3ec1883642bdfde01..c1ed03b78c622163aeb354ef4eb16b10810184da 100644 (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
index 02d29704bce91b50876a2239cd8dd696101829f0..7a5298f026ebe28cbfb89e60b1aca2da9d434dbf 100644 (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;
index b6bc1dc45de38c454e392dbc146304b55126606d..4bc01a586a34612614b312207b46bc26b0c0c3d0 100644 (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)
index 2e8efa89d4ba6bb59522ff3eac44db7997458583..32c35b7bf523b952f14b76e3f038295eefadc3c9 100644 (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;
 
 /*
diff --git a/src/testdir/dumps/Test_pum_highlights_13.dump b/src/testdir/dumps/Test_pum_highlights_13.dump
new file mode 100644 (file)
index 0000000..34fde12
--- /dev/null
@@ -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
diff --git a/src/testdir/dumps/Test_pum_highlights_14.dump b/src/testdir/dumps/Test_pum_highlights_14.dump
new file mode 100644 (file)
index 0000000..f35b4cb
--- /dev/null
@@ -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
index 67e600c4c0538cea30548150a411064d631a3e4f..4c2fb4542fea1ccfac6380e5b1953d36f643a6f5 100644 (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
 
index f2b7a19f366c00d28b8e86d7b519151a017bd7c8..a7b5405e431d7686ab0066e126f3e5cf96cd41b5 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    629,
 /**/
     628,
 /**/