summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-06-17 18:25:32 +0200
committerChristian Brabandt <cb@256bit.org>2024-06-17 18:25:32 +0200
commitd8c9340fc67ca19f82ec3e77ec38296424e758cf (patch)
tree40b666497cc92fc44b37316b8454aac1f1957441
parent84ac2126f470569c770cd22a52f8d48c50cd42a1 (diff)
patch 9.1.0495: Matched text isn't highlighted in cmdline pumv9.1.0495
Problem: Matched text isn't highlighted in cmdline pum. Solution: Use cmdline completion pattern in cmdline mode. (zeertzjq) closes: #15029 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--runtime/doc/version9.txt3
-rw-r--r--src/cmdexpand.c22
-rw-r--r--src/popupmenu.c17
-rw-r--r--src/proto/cmdexpand.pro2
-rw-r--r--src/testdir/dumps/Test_wildmenu_pum_hl_match_1.dump10
-rw-r--r--src/testdir/dumps/Test_wildmenu_pum_hl_match_2.dump10
-rw-r--r--src/testdir/dumps/Test_wildmenu_pum_hl_match_3.dump10
-rw-r--r--src/testdir/dumps/Test_wildmenu_pum_hl_match_4.dump10
-rw-r--r--src/testdir/dumps/Test_wildmenu_pum_hl_match_5.dump10
-rw-r--r--src/testdir/dumps/Test_wildmenu_pum_hl_match_6.dump10
-rw-r--r--src/testdir/test_cmdline.vim31
-rw-r--r--src/version.c2
12 files changed, 132 insertions, 5 deletions
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index 62152406e6..5b5bdede12 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -41560,6 +41560,9 @@ Support for Wayland UI.
Support for the XDG Desktop Specification |xdg-base-dir|
+Support highlighting the matched text for insert-mode completion and
+command-line completion in |ins-completion-menu|.
+
*changed-9.2*
Changed~
-------
diff --git a/src/cmdexpand.c b/src/cmdexpand.c
index 1008bf97e5..8d8bf06b5f 100644
--- a/src/cmdexpand.c
+++ b/src/cmdexpand.c
@@ -438,6 +438,28 @@ cmdline_compl_startcol(void)
}
/*
+ * Returns the current cmdline completion pattern.
+ */
+ char_u *
+cmdline_compl_pattern(void)
+{
+ expand_T *xp = get_cmdline_info()->xpc;
+
+ return xp == NULL ? NULL : xp->xp_orig;
+}
+
+/*
+ * Returns TRUE if fuzzy cmdline completion is active, FALSE otherwise.
+ */
+ int
+cmdline_compl_is_fuzzy(void)
+{
+ expand_T *xp = get_cmdline_info()->xpc;
+
+ return xp != NULL && cmdline_fuzzy_completion_supported(xp);
+}
+
+/*
* Return the number of characters that should be skipped in a status match.
* These are backslashes used for escaping. Do show backslashes in help tags.
*/
diff --git a/src/popupmenu.c b/src/popupmenu.c
index 8a4b68f020..fdec5f3ec2 100644
--- a/src/popupmenu.c
+++ b/src/popupmenu.c
@@ -428,28 +428,35 @@ pum_under_menu(int row, int col, int only_redrawing)
pum_compute_text_attrs(char_u *text, hlf_T hlf)
{
int i;
- int leader_len;
+ size_t leader_len;
int char_cells;
int new_attr;
char_u *ptr = text;
int cell_idx = 0;
garray_T *ga = NULL;
int *attrs = NULL;
- char_u *leader = ins_compl_leader();
- int in_fuzzy = (get_cot_flags() & COT_FUZZY) != 0;
+ char_u *leader = NULL;
+ int in_fuzzy;
int matched_start = FALSE;
int_u char_pos = 0;
- if (leader == NULL || *leader == NUL || (hlf != HLF_PSI && hlf != HLF_PNI)
+ if ((hlf != HLF_PSI && hlf != HLF_PNI)
|| (highlight_attr[HLF_PMSI] == highlight_attr[HLF_PSI]
&& highlight_attr[HLF_PMNI] == highlight_attr[HLF_PNI]))
return NULL;
+ leader = State == MODE_CMDLINE ? cmdline_compl_pattern()
+ : ins_compl_leader();
+ if (leader == NULL || *leader == NUL)
+ return NULL;
+
attrs = ALLOC_MULT(int, vim_strsize(text));
if (attrs == NULL)
return NULL;
- leader_len = (int)STRLEN(leader);
+ in_fuzzy = State == MODE_CMDLINE ? cmdline_compl_is_fuzzy()
+ : (get_cot_flags() & COT_FUZZY) != 0;
+ leader_len = STRLEN(leader);
if (in_fuzzy)
ga = fuzzy_match_str_with_pos(text, leader);
diff --git a/src/proto/cmdexpand.pro b/src/proto/cmdexpand.pro
index 100c23d66a..dfa6d1b96b 100644
--- a/src/proto/cmdexpand.pro
+++ b/src/proto/cmdexpand.pro
@@ -6,6 +6,8 @@ int cmdline_pum_active(void);
void cmdline_pum_remove(void);
void cmdline_pum_cleanup(cmdline_info_T *cclp);
int cmdline_compl_startcol(void);
+char_u *cmdline_compl_pattern(void);
+int cmdline_compl_is_fuzzy(void);
char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode);
void ExpandInit(expand_T *xp);
void ExpandCleanup(expand_T *xp);
diff --git a/src/testdir/dumps/Test_wildmenu_pum_hl_match_1.dump b/src/testdir/dumps/Test_wildmenu_pum_hl_match_1.dump
new file mode 100644
index 0000000000..077268206d
--- /dev/null
+++ b/src/testdir/dumps/Test_wildmenu_pum_hl_match_1.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@49
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @3| +0#0000001#e0e0e08|p+0#00e0e07&|l|a+0#0000001&|c+0#00e0e07&|e+0#0000001&| @9| +0#4040ff13#ffffff0@28
+|~| @3| +0#0000001#ffd7ff255|u|n|p+0#0000e05&|l|a+0#0000001&|c+0#0000e05&|e+0#0000001&| @7| +0#4040ff13#ffffff0@28
+|:+0#0000000&|s|i|g|n| |p|l|a|c|e> @38
diff --git a/src/testdir/dumps/Test_wildmenu_pum_hl_match_2.dump b/src/testdir/dumps/Test_wildmenu_pum_hl_match_2.dump
new file mode 100644
index 0000000000..ec781effa8
--- /dev/null
+++ b/src/testdir/dumps/Test_wildmenu_pum_hl_match_2.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@49
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @3| +0#0000001#ffd7ff255|p+0#0000e05&|l|a+0#0000001&|c+0#0000e05&|e+0#0000001&| @9| +0#4040ff13#ffffff0@28
+|~| @3| +0#0000001#e0e0e08|u|n|p+0#00e0e07&|l|a+0#0000001&|c+0#00e0e07&|e+0#0000001&| @7| +0#4040ff13#ffffff0@28
+|:+0#0000000&|s|i|g|n| |u|n|p|l|a|c|e> @36
diff --git a/src/testdir/dumps/Test_wildmenu_pum_hl_match_3.dump b/src/testdir/dumps/Test_wildmenu_pum_hl_match_3.dump
new file mode 100644
index 0000000000..afb792a1db
--- /dev/null
+++ b/src/testdir/dumps/Test_wildmenu_pum_hl_match_3.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@49
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @3| +0#0000001#ffd7ff255|p+0#0000e05&|l|a+0#0000001&|c+0#0000e05&|e+0#0000001&| @9| +0#4040ff13#ffffff0@28
+|~| @3| +0#0000001#ffd7ff255|u|n|p+0#0000e05&|l|a+0#0000001&|c+0#0000e05&|e+0#0000001&| @7| +0#4040ff13#ffffff0@28
+|:+0#0000000&|s|i|g|n| |p|l|c> @40
diff --git a/src/testdir/dumps/Test_wildmenu_pum_hl_match_4.dump b/src/testdir/dumps/Test_wildmenu_pum_hl_match_4.dump
new file mode 100644
index 0000000000..0be8053226
--- /dev/null
+++ b/src/testdir/dumps/Test_wildmenu_pum_hl_match_4.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@49
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @3| +0#0000001#e0e0e08|u+0#00e0e07&|n|d+0#0000001&|e|f|i|n|e| @6| +0#4040ff13#ffffff0@28
+|~| @3| +0#0000001#ffd7ff255|u+0#0000e05&|n|p+0#0000001&|l|a|c|e| @7| +0#4040ff13#ffffff0@28
+|:+0#0000000&|s|i|g|n| |u|n|d|e|f|i|n|e> @35
diff --git a/src/testdir/dumps/Test_wildmenu_pum_hl_match_5.dump b/src/testdir/dumps/Test_wildmenu_pum_hl_match_5.dump
new file mode 100644
index 0000000000..7453cb9de2
--- /dev/null
+++ b/src/testdir/dumps/Test_wildmenu_pum_hl_match_5.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@49
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @3| +0#0000001#ffd7ff255|u+0#0000e05&|n|d+0#0000001&|e|f|i|n|e| @6| +0#4040ff13#ffffff0@28
+|~| @3| +0#0000001#e0e0e08|u+0#00e0e07&|n|p+0#0000001&|l|a|c|e| @7| +0#4040ff13#ffffff0@28
+|:+0#0000000&|s|i|g|n| |u|n|p|l|a|c|e> @36
diff --git a/src/testdir/dumps/Test_wildmenu_pum_hl_match_6.dump b/src/testdir/dumps/Test_wildmenu_pum_hl_match_6.dump
new file mode 100644
index 0000000000..8345007951
--- /dev/null
+++ b/src/testdir/dumps/Test_wildmenu_pum_hl_match_6.dump
@@ -0,0 +1,10 @@
+| +0&#ffffff0@49
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @48
+|~| @3| +0#0000001#ffd7ff255|u+0#0000e05&|n|d+0#0000001&|e|f|i|n|e| @6| +0#4040ff13#ffffff0@28
+|~| @3| +0#0000001#ffd7ff255|u+0#0000e05&|n|p+0#0000001&|l|a|c|e| @7| +0#4040ff13#ffffff0@28
+|:+0#0000000&|s|i|g|n| |u|n> @41
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 150c40d3f8..8b7489ea46 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -2759,6 +2759,37 @@ func Test_wildmenu_pum_rightleft()
call StopVimInTerminal(buf)
endfunc
+" Test highlighting matched text in cmdline completion popup menu.
+func Test_wildmenu_pum_hl_match()
+ CheckScreendump
+
+ let lines =<< trim END
+ set wildoptions=pum,fuzzy
+ hi PmenuMatchSel ctermfg=6 ctermbg=7
+ hi PmenuMatch ctermfg=4 ctermbg=225
+ END
+ call writefile(lines, 'Xwildmenu_pum_hl', 'D')
+ let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
+
+ call term_sendkeys(buf, ":sign plc\<Tab>")
+ call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
+ call term_sendkeys(buf, "\<Tab>")
+ call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
+ call term_sendkeys(buf, "\<Tab>")
+ call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
+ call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
+ call TermWait(buf)
+ call term_sendkeys(buf, ":sign un\<Tab>")
+ call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
+ call term_sendkeys(buf, "\<Tab>")
+ call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
+ call term_sendkeys(buf, "\<Tab>")
+ call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call StopVimInTerminal(buf)
+endfunc
+
" Test for completion after a :substitute command followed by a pipe (|)
" character
func Test_cmdline_complete_substitute()
diff --git a/src/version.c b/src/version.c
index 0ca2bf2202..3565696613 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 495,
+/**/
494,
/**/
493,