mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.1.0495: Matched text isn't highlighted in cmdline pum
Problem: Matched text isn't highlighted in cmdline pum.
Solution: Use cmdline completion pattern in cmdline mode.
(zeertzjq)
closes: vim/vim#15029
d8c9340fc6
Cherry-pick syntax.txt change from runtime update.
This commit is contained in:
@@ -5075,9 +5075,9 @@ PmenuSbar Popup menu: Scrollbar.
|
||||
*hl-PmenuThumb*
|
||||
PmenuThumb Popup menu: Thumb of the scrollbar.
|
||||
*hl-PmenuMatch*
|
||||
PmenuMatch Popup menu: Matched text in normal item
|
||||
PmenuMatch Popup menu: Matched text in normal item.
|
||||
*hl-PmenuMatchSel*
|
||||
PmenuMatchSel Popup menu: Matched text in selected item
|
||||
PmenuMatchSel Popup menu: Matched text in selected item.
|
||||
*hl-Question*
|
||||
Question |hit-enter| prompt and yes/no questions.
|
||||
*hl-QuickFixLine*
|
||||
|
@@ -402,6 +402,20 @@ void cmdline_pum_cleanup(CmdlineInfo *cclp)
|
||||
wildmenu_cleanup(cclp);
|
||||
}
|
||||
|
||||
/// Returns the current cmdline completion pattern.
|
||||
char *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.
|
||||
bool 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 the wildmenu
|
||||
/// These are backslashes used for escaping. Do show backslashes in help tags.
|
||||
static int skip_wildmenu_char(expand_T *xp, char *s)
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "nvim/buffer_updates.h"
|
||||
#include "nvim/change.h"
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/cmdexpand.h"
|
||||
#include "nvim/drawscreen.h"
|
||||
#include "nvim/edit.h"
|
||||
#include "nvim/errors.h"
|
||||
@@ -441,17 +442,21 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
|
||||
/// Returns attributes for every cell, or NULL if all attributes are the same.
|
||||
static int *pum_compute_text_attrs(char *text, hlf_T hlf)
|
||||
{
|
||||
char *leader = ins_compl_leader();
|
||||
|
||||
if (leader == NULL || *leader == NUL || (hlf != HLF_PSI && hlf != HLF_PNI)
|
||||
if ((hlf != HLF_PSI && hlf != HLF_PNI)
|
||||
|| (win_hl_attr(curwin, HLF_PMSI) == win_hl_attr(curwin, HLF_PSI)
|
||||
&& win_hl_attr(curwin, HLF_PMNI) == win_hl_attr(curwin, HLF_PNI))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *leader = State == MODE_CMDLINE ? cmdline_compl_pattern() : ins_compl_leader();
|
||||
if (leader == NULL || *leader == NUL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int *attrs = xmalloc(sizeof(int) * (size_t)vim_strsize(text));
|
||||
bool in_fuzzy = State == MODE_CMDLINE ? cmdline_compl_is_fuzzy()
|
||||
: (get_cot_flags() & COT_FUZZY) != 0;
|
||||
size_t leader_len = strlen(leader);
|
||||
const bool in_fuzzy = (get_cot_flags() & COT_FUZZY) != 0;
|
||||
|
||||
garray_T *ga = NULL;
|
||||
bool matched_start = false;
|
||||
|
@@ -3550,6 +3550,66 @@ describe('builtin popupmenu', function()
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_wildmenu_pum_hl_match()
|
||||
it('highlighting matched text in cmdline pum', function()
|
||||
exec([[
|
||||
set wildoptions=pum,fuzzy
|
||||
hi PmenuMatchSel guifg=Blue guibg=Grey
|
||||
hi PmenuMatch guifg=Blue guibg=Magenta
|
||||
]])
|
||||
|
||||
feed(':sign plc<Tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|*16
|
||||
{1:~ }{s: }{ms:pl}{s:a}{ms:c}{s:e }{1: }|
|
||||
{1:~ }{n: un}{mn:pl}{n:a}{mn:c}{n:e }{1: }|
|
||||
:sign place^ |
|
||||
]])
|
||||
feed('<Tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|*16
|
||||
{1:~ }{n: }{mn:pl}{n:a}{mn:c}{n:e }{1: }|
|
||||
{1:~ }{s: un}{ms:pl}{s:a}{ms:c}{s:e }{1: }|
|
||||
:sign unplace^ |
|
||||
]])
|
||||
feed('<Tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|*16
|
||||
{1:~ }{n: }{mn:pl}{n:a}{mn:c}{n:e }{1: }|
|
||||
{1:~ }{n: un}{mn:pl}{n:a}{mn:c}{n:e }{1: }|
|
||||
:sign plc^ |
|
||||
]])
|
||||
feed('<Esc>')
|
||||
command('set wildoptions-=fuzzy')
|
||||
feed(':sign un<Tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|*16
|
||||
{1:~ }{s: }{ms:un}{s:define }{1: }|
|
||||
{1:~ }{n: }{mn:un}{n:place }{1: }|
|
||||
:sign undefine^ |
|
||||
]])
|
||||
feed('<Tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|*16
|
||||
{1:~ }{n: }{mn:un}{n:define }{1: }|
|
||||
{1:~ }{s: }{ms:un}{s:place }{1: }|
|
||||
:sign unplace^ |
|
||||
]])
|
||||
feed('<Tab>')
|
||||
screen:expect([[
|
||||
|
|
||||
{1:~ }|*16
|
||||
{1:~ }{n: }{mn:un}{n:define }{1: }|
|
||||
{1:~ }{n: }{mn:un}{n:place }{1: }|
|
||||
:sign un^ |
|
||||
]])
|
||||
end)
|
||||
end
|
||||
|
||||
it("'pumheight'", function()
|
||||
|
@@ -2923,6 +2923,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()
|
||||
|
Reference in New Issue
Block a user