vim-patch:9.1.0619: tests: test_popup fails

Problem:  tests: test_popup fails
          (after v9.1.0618)
Solution: Correct test, move combining extra attributes to
          pum_compute_text_attrs() (glepnir)

closes: vim/vim#15353

8754efe437

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
glepnir 2024-07-27 18:06:21 +08:00
parent f132f8e9d4
commit bc8a776ef8
2 changed files with 10 additions and 10 deletions

View File

@ -440,7 +440,7 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
/// Computes attributes of text on the popup menu. /// Computes attributes of text on the popup menu.
/// Returns attributes for every cell, or NULL if all attributes are the same. /// Returns attributes for every cell, or NULL if all attributes are the same.
static int *pum_compute_text_attrs(char *text, hlf_T hlf) static int *pum_compute_text_attrs(char *text, hlf_T hlf, int extra_hlattr)
{ {
if ((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_PMSI) == win_hl_attr(curwin, HLF_PSI)
@ -486,6 +486,9 @@ static int *pum_compute_text_attrs(char *text, hlf_T hlf)
} else if (matched_start && ptr < text + leader_len) { } else if (matched_start && ptr < text + leader_len) {
new_attr = win_hl_attr(curwin, hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI); new_attr = win_hl_attr(curwin, hlf == HLF_PSI ? HLF_PMSI : HLF_PMNI);
} }
if (extra_hlattr > 0) {
new_attr = hl_combine_attr(new_attr, extra_hlattr);
}
int char_cells = utf_ptr2cells(ptr); int char_cells = utf_ptr2cells(ptr);
for (int i = 0; i < char_cells; i++) { for (int i = 0; i < char_cells; i++) {
@ -506,7 +509,7 @@ static int *pum_compute_text_attrs(char *text, hlf_T hlf)
/// Displays text on the popup menu with specific attributes. /// Displays text on the popup menu with specific attributes.
static void pum_grid_puts_with_attrs(int col, int cells, const char *text, int textlen, static void pum_grid_puts_with_attrs(int col, int cells, const char *text, int textlen,
const int *attrs, int extra_hlattr) const int *attrs)
{ {
const int col_start = col; const int col_start = col;
const char *ptr = text; const char *ptr = text;
@ -515,9 +518,6 @@ static void pum_grid_puts_with_attrs(int col, int cells, const char *text, int t
while (*ptr != NUL && (textlen < 0 || ptr < text + textlen)) { while (*ptr != NUL && (textlen < 0 || ptr < text + textlen)) {
int char_len = utfc_ptr2len(ptr); int char_len = utfc_ptr2len(ptr);
int attr = attrs[pum_rl ? (col_start + cells - col - 1) : (col - col_start)]; int attr = attrs[pum_rl ? (col_start + cells - col - 1) : (col - col_start)];
if (extra_hlattr > 0) {
attr = hl_combine_attr(extra_hlattr , attr);
}
grid_line_puts(col, ptr, char_len, attr); grid_line_puts(col, ptr, char_len, attr);
col += utf_ptr2cells(ptr); col += utf_ptr2cells(ptr);
ptr += char_len; ptr += char_len;
@ -666,7 +666,7 @@ void pum_redraw(void)
*p = saved; *p = saved;
} }
int *attrs = pum_compute_text_attrs(st, hlf); int *attrs = pum_compute_text_attrs(st, hlf, pum_array[idx].pum_extrahlattr);
if (pum_rl) { if (pum_rl) {
char *rt = reverse_text(st); char *rt = reverse_text(st);
@ -691,7 +691,7 @@ void pum_redraw(void)
if (attrs == NULL) { if (attrs == NULL) {
grid_line_puts(grid_col - cells + 1, rt, -1, attr); grid_line_puts(grid_col - cells + 1, rt, -1, attr);
} else { } else {
pum_grid_puts_with_attrs(grid_col - cells + 1, cells, rt, -1, attrs, pum_array[idx].pum_extrahlattr); pum_grid_puts_with_attrs(grid_col - cells + 1, cells, rt, -1, attrs);
} }
xfree(rt_start); xfree(rt_start);
@ -701,7 +701,7 @@ void pum_redraw(void)
if (attrs == NULL) { if (attrs == NULL) {
grid_line_puts(grid_col, st, -1, attr); grid_line_puts(grid_col, st, -1, attr);
} else { } else {
pum_grid_puts_with_attrs(grid_col, vim_strsize(st), st, -1, attrs, pum_array[idx].pum_extrahlattr); pum_grid_puts_with_attrs(grid_col, vim_strsize(st), st, -1, attrs);
} }
xfree(st); xfree(st);

View File

@ -1516,9 +1516,9 @@ func Test_pum_extrahl()
endif endif
return { return {
\ 'words': [ \ 'words': [
\ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'extrahl': 'StrikeFake' }, \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', 'hl_group': 'StrikeFake' },
\ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', },
\ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'extrahl': 'StrikeFake' }, \ { 'word': '你好', 'menu': 'extra text 3', 'kind': 'W', 'hl_group': 'StrikeFake' },
\]} \]}
endfunc endfunc
set completeopt=menu set completeopt=menu