mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1397: highlight for popupmenu kind and extra cannot be set (#22619)
Problem: Highlight for popupmenu kind and extra cannot be set.
Solution: Add PmenuKind, PmenuKindSel, PmenuExtra and PmenuExtraSel
highlight groups and use them. (Gianmaria Bajo, closes vim/vim#12114)
6a7c774920
Co-authored-by: Gianmaria Bajo <mg1979.git@gmail.com>
This commit is contained in:
parent
29a43ef8af
commit
8cb5b995b6
@ -5278,6 +5278,14 @@ NormalNC Normal text in non-current windows.
|
||||
Pmenu Popup menu: Normal item.
|
||||
*hl-PmenuSel*
|
||||
PmenuSel Popup menu: Selected item.
|
||||
*hl-PmenuKind*
|
||||
PmenuKind Popup menu: Normal item "kind".
|
||||
*hl-PmenuKindSel*
|
||||
PmenuKindSel Popup menu: Selected item "kind".
|
||||
*hl-PmenuExtra*
|
||||
PmenuExtra Popup menu: Normal item "extra text".
|
||||
*hl-PmenuExtraSel*
|
||||
PmenuExtraSel Popup menu: Selected item "extra text".
|
||||
*hl-PmenuSbar*
|
||||
PmenuSbar Popup menu: Scrollbar.
|
||||
*hl-PmenuThumb*
|
||||
|
@ -100,6 +100,10 @@ typedef enum {
|
||||
HLF_SPL, // SpellLocal
|
||||
HLF_PNI, // popup menu normal item
|
||||
HLF_PSI, // popup menu selected item
|
||||
HLF_PNK, // popup menu normal item "kind"
|
||||
HLF_PSK, // popup menu selected item "kind"
|
||||
HLF_PNX, // popup menu normal item "menu" (extra text)
|
||||
HLF_PSX, // popup menu selected item "menu" (extra text)
|
||||
HLF_PSB, // popup menu scrollbar
|
||||
HLF_PST, // popup menu scrollbar thumb
|
||||
HLF_TP, // tabpage line
|
||||
@ -165,6 +169,10 @@ EXTERN const char *hlf_names[] INIT(= {
|
||||
[HLF_SPL] = "SpellLocal",
|
||||
[HLF_PNI] = "Pmenu",
|
||||
[HLF_PSI] = "PmenuSel",
|
||||
[HLF_PNK] = "PmenuKind",
|
||||
[HLF_PSK] = "PmenuKindSel",
|
||||
[HLF_PNX] = "PmenuExtra",
|
||||
[HLF_PSX] = "PmenuExtraSel",
|
||||
[HLF_PSB] = "PmenuSbar",
|
||||
[HLF_PST] = "PmenuThumb",
|
||||
[HLF_TP] = "TabLine",
|
||||
|
@ -150,6 +150,10 @@ static const char *highlight_init_both[] = {
|
||||
"default link QuickFixLine Search",
|
||||
"default link CursorLineSign SignColumn",
|
||||
"default link CursorLineFold FoldColumn",
|
||||
"default link PmenuKind Pmenu",
|
||||
"default link PmenuKindSel PmenuSel",
|
||||
"default link PmenuExtra Pmenu",
|
||||
"default link PmenuExtraSel PmenuSel",
|
||||
"default link Substitute Search",
|
||||
"default link Whitespace NonText",
|
||||
"default link MsgSeparator StatusLine",
|
||||
|
@ -92,8 +92,9 @@ typedef enum {
|
||||
"N:CursorLineNr,G:CursorLineSign,O:CursorLineFold" \
|
||||
"r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg," \
|
||||
"W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn," \
|
||||
"-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar," \
|
||||
"X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn," \
|
||||
"-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \
|
||||
"[:PmenuKind,]:PmenuKindSel,{:PmenuExtra,}:PmenuExtraSel,x:PmenuSbar,X:PmenuThumb," \
|
||||
"*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn," \
|
||||
"q:QuickFixLine,0:Whitespace,I:NormalNC"
|
||||
|
||||
// Default values for 'errorformat'.
|
||||
|
@ -407,8 +407,6 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
|
||||
void pum_redraw(void)
|
||||
{
|
||||
int row = 0;
|
||||
int attr_norm = win_hl_attr(curwin, HLF_PNI);
|
||||
int attr_select = win_hl_attr(curwin, HLF_PSI);
|
||||
int attr_scroll = win_hl_attr(curwin, HLF_PSB);
|
||||
int attr_thumb = win_hl_attr(curwin, HLF_PST);
|
||||
int i;
|
||||
@ -418,9 +416,14 @@ void pum_redraw(void)
|
||||
int w;
|
||||
int thumb_pos = 0;
|
||||
int thumb_height = 1;
|
||||
int round;
|
||||
int n;
|
||||
|
||||
#define HA(hlf) (win_hl_attr(curwin, (hlf)))
|
||||
// "word" "kind" "extra text"
|
||||
const int attrsNorm[3] = { HA(HLF_PNI), HA(HLF_PNK), HA(HLF_PNX) };
|
||||
const int attrsSel[3] = { HA(HLF_PSI), HA(HLF_PSK), HA(HLF_PSX) };
|
||||
#undef HA
|
||||
|
||||
int grid_width = pum_width;
|
||||
int col_off = 0;
|
||||
bool extra_space = false;
|
||||
@ -482,7 +485,8 @@ void pum_redraw(void)
|
||||
|
||||
for (i = 0; i < pum_height; i++) {
|
||||
int idx = i + pum_first;
|
||||
int attr = (idx == pum_selected) ? attr_select : attr_norm;
|
||||
const int *const attrs = (idx == pum_selected) ? attrsSel : attrsNorm;
|
||||
int attr = attrs[0]; // start with "word" highlight
|
||||
|
||||
grid_puts_line_start(&pum_grid, row);
|
||||
|
||||
@ -496,26 +500,25 @@ void pum_redraw(void)
|
||||
}
|
||||
|
||||
// Display each entry, use two spaces for a Tab.
|
||||
// Do this 3 times: For the main text, kind and extra info
|
||||
// Do this 3 times:
|
||||
// 0 - main text
|
||||
// 1 - kind
|
||||
// 2 - extra info
|
||||
int grid_col = col_off;
|
||||
int totwidth = 0;
|
||||
|
||||
for (round = 1; round <= 3; round++) {
|
||||
for (int round = 0; round < 3; round++) {
|
||||
attr = attrs[round];
|
||||
width = 0;
|
||||
s = NULL;
|
||||
|
||||
switch (round) {
|
||||
case 0:
|
||||
p = pum_array[idx].pum_text; break;
|
||||
case 1:
|
||||
p = pum_array[idx].pum_text;
|
||||
break;
|
||||
|
||||
p = pum_array[idx].pum_kind; break;
|
||||
case 2:
|
||||
p = pum_array[idx].pum_kind;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
p = pum_array[idx].pum_extra;
|
||||
break;
|
||||
p = pum_array[idx].pum_extra; break;
|
||||
}
|
||||
|
||||
if (p != NULL) {
|
||||
@ -592,17 +595,17 @@ void pum_redraw(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (round > 1) {
|
||||
if (round > 0) {
|
||||
n = pum_kind_width + 1;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
|
||||
// Stop when there is nothing more to display.
|
||||
if ((round == 3)
|
||||
|| ((round == 2)
|
||||
&& (pum_array[idx].pum_extra == NULL))
|
||||
if ((round == 2)
|
||||
|| ((round == 1)
|
||||
&& (pum_array[idx].pum_extra == NULL))
|
||||
|| ((round == 0)
|
||||
&& (pum_array[idx].pum_kind == NULL)
|
||||
&& (pum_array[idx].pum_extra == NULL))
|
||||
|| (pum_base_width + n >= pum_width)) {
|
||||
|
@ -212,10 +212,10 @@ describe('ui/cursor', function()
|
||||
if m.blinkwait then m.blinkwait = 700 end
|
||||
end
|
||||
if m.hl_id then
|
||||
m.hl_id = 60
|
||||
m.hl_id = 64
|
||||
m.attr = {background = Screen.colors.DarkGray}
|
||||
end
|
||||
if m.id_lm then m.id_lm = 62 end
|
||||
if m.id_lm then m.id_lm = 66 end
|
||||
end
|
||||
|
||||
-- Assert the new expectation.
|
||||
|
@ -3490,6 +3490,68 @@ describe('builtin popupmenu', function()
|
||||
pasted |
|
||||
]])
|
||||
end)
|
||||
|
||||
describe('"kind" and "menu"', function()
|
||||
before_each(function()
|
||||
screen:try_resize(30, 8)
|
||||
exec([[
|
||||
func CompleteFunc( findstart, base )
|
||||
if a:findstart
|
||||
return 0
|
||||
endif
|
||||
return {
|
||||
\ 'words': [
|
||||
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
|
||||
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
|
||||
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
|
||||
\]}
|
||||
endfunc
|
||||
set completeopt=menu
|
||||
set completefunc=CompleteFunc
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_pum_highlights_default()
|
||||
it('default highlight groups', function()
|
||||
feed('iaw<C-X><C-u>')
|
||||
screen:expect([[
|
||||
aword1^ |
|
||||
{s:aword1 W extra text 1 }{1: }|
|
||||
{n:aword2 W extra text 2 }{1: }|
|
||||
{n:aword3 W extra text 3 }{1: }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- }{5:match 1 of 3} |
|
||||
]])
|
||||
end)
|
||||
|
||||
-- oldtest: Test_pum_highlights_custom()
|
||||
it('custom highlight groups', function()
|
||||
exec([[
|
||||
hi PmenuKind guifg=Red guibg=Magenta
|
||||
hi PmenuKindSel guifg=Red guibg=Grey
|
||||
hi PmenuExtra guifg=White guibg=Magenta
|
||||
hi PmenuExtraSel guifg=Black guibg=Grey
|
||||
]])
|
||||
local attrs = screen:get_default_attr_ids()
|
||||
attrs.kn = {foreground = Screen.colors.Red, background = Screen.colors.Magenta}
|
||||
attrs.ks = {foreground = Screen.colors.Red, background = Screen.colors.Grey}
|
||||
attrs.xn = {foreground = Screen.colors.White, background = Screen.colors.Magenta}
|
||||
attrs.xs = {foreground = Screen.colors.Black, background = Screen.colors.Grey}
|
||||
feed('iaw<C-X><C-u>')
|
||||
screen:expect([[
|
||||
aword1^ |
|
||||
{s:aword1 }{ks:W }{xs:extra text 1 }{1: }|
|
||||
{n:aword2 }{kn:W }{xn:extra text 2 }{1: }|
|
||||
{n:aword3 }{kn:W }{xn:extra text 3 }{1: }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- }{5:match 1 of 3} |
|
||||
]], attrs)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('builtin popupmenu with ui/ext_multigrid', function()
|
||||
|
@ -1260,4 +1260,66 @@ func Test_pum_scrollbar()
|
||||
call delete('Xtest1')
|
||||
endfunc
|
||||
|
||||
" Test default highlight groups for popup menu
|
||||
func Test_pum_highlights_default()
|
||||
CheckScreendump
|
||||
let lines =<< trim END
|
||||
func CompleteFunc( findstart, base )
|
||||
if a:findstart
|
||||
return 0
|
||||
endif
|
||||
return {
|
||||
\ 'words': [
|
||||
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
|
||||
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
|
||||
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
|
||||
\]}
|
||||
endfunc
|
||||
set completeopt=menu
|
||||
set completefunc=CompleteFunc
|
||||
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 VerifyScreenDump(buf, 'Test_pum_highlights_01', {})
|
||||
call term_sendkeys(buf, "\<C-E>\<Esc>u")
|
||||
call TermWait(buf)
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" Test custom highlight groups for popup menu
|
||||
func Test_pum_highlights_custom()
|
||||
CheckScreendump
|
||||
let lines =<< trim END
|
||||
func CompleteFunc( findstart, base )
|
||||
if a:findstart
|
||||
return 0
|
||||
endif
|
||||
return {
|
||||
\ 'words': [
|
||||
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', },
|
||||
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
|
||||
\ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', },
|
||||
\]}
|
||||
endfunc
|
||||
set completeopt=menu
|
||||
set completefunc=CompleteFunc
|
||||
hi PmenuKind ctermfg=1 ctermbg=225
|
||||
hi PmenuKindSel ctermfg=1 ctermbg=7
|
||||
hi PmenuExtra ctermfg=243 ctermbg=225
|
||||
hi PmenuExtraSel ctermfg=0 ctermbg=7
|
||||
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 VerifyScreenDump(buf, 'Test_pum_highlights_02', {})
|
||||
call term_sendkeys(buf, "\<C-E>\<Esc>u")
|
||||
call TermWait(buf)
|
||||
call StopVimInTerminal(buf)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Loading…
Reference in New Issue
Block a user