vim-patch:9.1.1398: completion: trunc does not follow Pmenu highlighting attributes (#34084)

Problem:  When items are combined with user-defined highlight attributes
          (e.g., strikethrough), trunc inherits these attributes, making
          the text difficult to read.
Solution: trunc now uses the original Pmenu and PmenuSel highlight
          attributes (glepnir)

closes: vim/vim#17340

0816f17e9a

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
zeertzjq
2025-05-19 08:11:54 +08:00
committed by GitHub
parent 3a35fdc347
commit dc6885dc24
3 changed files with 57 additions and 3 deletions

View File

@@ -651,7 +651,9 @@ void pum_redraw(void)
for (int i = 0; i < pum_height; i++) { for (int i = 0; i < pum_height; i++) {
int idx = i + pum_first; int idx = i + pum_first;
const hlf_T *const hlfs = (idx == pum_selected) ? hlfsSel : hlfsNorm; const bool selected = idx == pum_selected;
const hlf_T *const hlfs = selected ? hlfsSel : hlfsNorm;
const int trunc_attr = win_hl_attr(curwin, selected ? HLF_PSI : HLF_PNI);
hlf_T hlf = hlfs[0]; // start with "word" highlight hlf_T hlf = hlfs[0]; // start with "word" highlight
int attr = win_hl_attr(curwin, (int)hlf); int attr = win_hl_attr(curwin, (int)hlf);
attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), attr); attr = hl_combine_attr(win_hl_attr(curwin, HLF_PNI), attr);
@@ -825,6 +827,7 @@ void pum_redraw(void)
grid_line_fill(lcol, grid_col + 1, schar_from_ascii(' '), orig_attr); grid_line_fill(lcol, grid_col + 1, schar_from_ascii(' '), orig_attr);
if (need_fcs_trunc) { if (need_fcs_trunc) {
linebuf_char[lcol] = fcs_trunc != NUL ? fcs_trunc : schar_from_ascii('<'); linebuf_char[lcol] = fcs_trunc != NUL ? fcs_trunc : schar_from_ascii('<');
linebuf_attr[lcol] = trunc_attr;
if (pum_width > 1 && linebuf_char[lcol + 1] == NUL) { if (pum_width > 1 && linebuf_char[lcol + 1] == NUL) {
linebuf_char[lcol + 1] = schar_from_ascii(' '); linebuf_char[lcol + 1] = schar_from_ascii(' ');
} }
@@ -837,6 +840,7 @@ void pum_redraw(void)
linebuf_char[rcol - 2] = schar_from_ascii(' '); linebuf_char[rcol - 2] = schar_from_ascii(' ');
} }
linebuf_char[rcol - 1] = fcs_trunc != NUL ? fcs_trunc : schar_from_ascii('>'); linebuf_char[rcol - 1] = fcs_trunc != NUL ? fcs_trunc : schar_from_ascii('>');
linebuf_attr[rcol - 1] = trunc_attr;
} }
} }

View File

@@ -5810,6 +5810,7 @@ describe('builtin popupmenu', function()
it("'pummaxwidth' with multibyte", function() it("'pummaxwidth' with multibyte", function()
screen:try_resize(60, 8) screen:try_resize(60, 8)
exec([[ exec([[
hi StrikeFake guifg=DarkRed
let g:change = 0 let g:change = 0
func Omni_test(findstart, base) func Omni_test(findstart, base)
if a:findstart if a:findstart
@@ -5834,8 +5835,14 @@ describe('builtin popupmenu', function()
\ #{word: "bar", menu: "fooMenu", kind: "一二三四"}, \ #{word: "bar", menu: "fooMenu", kind: "一二三四"},
\ #{word: "一二三四五", kind: "multi"}, \ #{word: "一二三四五", kind: "multi"},
\ ] \ ]
else
return [#{word: "bar", menu: "fooMenu", kind: "一二三"}] return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
elseif g:change == 3
return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
else
return [
\ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"},
\ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"},
\ ]
endif endif
endfunc endfunc
set omnifunc=Omni_test set omnifunc=Omni_test
@@ -6399,6 +6406,36 @@ describe('builtin popupmenu', function()
end end
feed('<Esc>') feed('<Esc>')
command('set norightleft') command('set norightleft')
command('let g:change=4')
feed('S<C-X><C-O>')
if multigrid then
screen:expect({
grid = [[
## grid 1
[2:--------------------------------]|*19
[3:--------------------------------]|
## grid 2
一二三四五六七八九十^ |
{1:~ }|*18
## grid 3
{2:-- }{5:match 1 of 2} |
## grid 4
{ds:一二三四五六七 }{s:>}|
{dn:123456789_12345}{n:>}|
]],
float_pos = { [4] = { -1, 'NW', 2, 1, 0, false, 100, 1, 1, 0 } },
})
else
screen:expect([[
一二三四五六七八九十^ |
{ds:一二三四五六七 }{s:>}{1: }|
{dn:123456789_12345}{n:>}{1: }|
{1:~ }|*16
{2:-- }{5:match 1 of 2} |
]])
end
feed('<Esc>')
end) end)
it('does not crash when displayed in last column with rightleft #12032', function() it('does not crash when displayed in last column with rightleft #12032', function()

View File

@@ -2036,6 +2036,7 @@ func Test_pum_maxwidth_multibyte()
CheckScreendump CheckScreendump
let lines =<< trim END let lines =<< trim END
hi StrikeFake ctermfg=9
let g:change = 0 let g:change = 0
func Omni_test(findstart, base) func Omni_test(findstart, base)
if a:findstart if a:findstart
@@ -2060,8 +2061,14 @@ func Test_pum_maxwidth_multibyte()
\ #{word: "bar", menu: "fooMenu", kind: "一二三四"}, \ #{word: "bar", menu: "fooMenu", kind: "一二三四"},
\ #{word: "一二三四五", kind: "multi"}, \ #{word: "一二三四五", kind: "multi"},
\ ] \ ]
else
return [#{word: "bar", menu: "fooMenu", kind: "一二三"}] return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
elseif g:change == 3
return [#{word: "bar", menu: "fooMenu", kind: "一二三"}]
else
return [
\ #{word: "一二三四五六七八九十", abbr_hlgroup: "StrikeFake"},
\ #{word: "123456789_123456789_123456789_", abbr_hlgroup: "StrikeFake"},
\ ]
endif endif
endfunc endfunc
set omnifunc=Omni_test set omnifunc=Omni_test
@@ -2174,6 +2181,12 @@ func Test_pum_maxwidth_multibyte()
call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>")
endif endif
call term_sendkeys(buf, ":let g:change=4\<CR>")
call TermWait(buf, 50)
call term_sendkeys(buf, "S\<C-X>\<C-O>")
call VerifyScreenDump(buf, 'Test_pum_maxwidth_23', {'rows': 8})
call term_sendkeys(buf, "\<ESC>")
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc