diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-03-11 10:05:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 10:05:47 +0800 |
commit | 8cb5b995b6e4d86035e6950d92c0c68ab4e46787 (patch) | |
tree | f82e021bea111cc4ad18a16c52f72efcde1e6c8b /src | |
parent | 29a43ef8affbb9ecbae03b75db346205ffe9ec14 (diff) | |
download | rneovim-8cb5b995b6e4d86035e6950d92c0c68ab4e46787.tar.gz rneovim-8cb5b995b6e4d86035e6950d92c0c68ab4e46787.tar.bz2 rneovim-8cb5b995b6e4d86035e6950d92c0c68ab4e46787.zip |
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)
https://github.com/vim/vim/commit/6a7c7749204b256e779c245b1e999bf852ad7b64
Co-authored-by: Gianmaria Bajo <mg1979.git@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/highlight_defs.h | 8 | ||||
-rw-r--r-- | src/nvim/highlight_group.c | 4 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 5 | ||||
-rw-r--r-- | src/nvim/popupmenu.c | 41 |
4 files changed, 37 insertions, 21 deletions
diff --git a/src/nvim/highlight_defs.h b/src/nvim/highlight_defs.h index 95c81ac9db..a5586659c7 100644 --- a/src/nvim/highlight_defs.h +++ b/src/nvim/highlight_defs.h @@ -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", diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 70ee6c757c..5d8649b429 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -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", diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 0c78d7ada5..470eae2090 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -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'. diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c index cdf8d5720b..8db36e594c 100644 --- a/src/nvim/popupmenu.c +++ b/src/nvim/popupmenu.c @@ -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)) { |