patch 9.1.1398: completion: trunc does not follow Pmenu highlighting attributes
Commit: https://github.com/vim/vim/commit/0816f17e9a2ba2d1e132497b03905878c7340a78 Author: glepnir <glephun...@gmail.com> Date: Sun May 18 20:14:53 2025 +0200 patch 9.1.1398: completion: trunc does not follow Pmenu highlighting attributes 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: #17340 Signed-off-by: glepnir <glephun...@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/popupmenu.c b/src/popupmenu.c index d62904948..6d91c33ee 100644 --- a/src/popupmenu.c +++ b/src/popupmenu.c @@ -589,14 +589,16 @@ pum_display_rtl_text( int width, int width_limit, int totwidth, - int next_isempty) + int next_isempty, + int selected) { - char_u *rt; - int cells; + char_u *rt = NULL; + int cells = 0; int over_cell = 0; int truncated = FALSE; int pad = next_isempty ? 0 : 2; - int remaining; + int remaining = 0; + int trunc_attr = highlight_attr[selected ? HLF_PSI : HLF_PNI]; int truncrl = curwin->w_fill_chars.truncrl != NUL ? curwin->w_fill_chars.truncrl : '<'; @@ -656,7 +658,8 @@ pum_display_rtl_text( width = cells + over_cell + 1; rt = orig_rt; - screen_putchar(truncrl, row, col - width + 1 + TPL_LCOL(NULL), attr); + screen_putchar(truncrl, row, + col - width + 1 + TPL_LCOL(NULL), trunc_attr); if (over_cell > 0) screen_fill(row, row + 1, col - width + 2 + TPL_LCOL(NULL), @@ -691,15 +694,17 @@ pum_display_ltr_text( int width, // width already calculated in outer loop int width_limit, int totwidth, - int next_isempty) + int next_isempty, + int selected) { - int size; - int cells; + int size = 0; + int cells = 0; char_u *st_end = NULL; int over_cell = 0; int pad = next_isempty ? 0 : 2; - int truncated; - int remaining; + int truncated = FALSE; + int remaining = 0; + int trunc_attr = highlight_attr[selected ? HLF_PSI : HLF_PNI]; int trunc = curwin->w_fill_chars.trunc != NUL ? curwin->w_fill_chars.trunc : '>'; @@ -756,7 +761,8 @@ pum_display_ltr_text( screen_fill(row, row + 1, col + cells + TPL_LCOL(NULL), col + cells + over_cell + TPL_LCOL(NULL), ' ', ' ', attr); - screen_putchar(trunc, row, col + cells + over_cell + TPL_LCOL(NULL), attr); + screen_putchar(trunc, row, + col + cells + over_cell + TPL_LCOL(NULL), trunc_attr); } VIM_CLEAR(st); @@ -785,6 +791,7 @@ pum_process_item( char_u *p = pum_get_item(idx, item_type); int width = 0; // item width int w; // char width + int selected = idx == pum_selected; for ( ; ; MB_PTR_ADV(p)) { @@ -815,11 +822,11 @@ pum_process_item( #ifdef FEAT_RIGHTLEFT if (pum_rl) col = pum_display_rtl_text(row, col, st, attr, attrs, - width, pum_width, *totwidth_ptr, next_isempty); + width, pum_width, *totwidth_ptr, next_isempty, selected); else #endif col = pum_display_ltr_text(row, col, st, attr, attrs, - width, pum_width, *totwidth_ptr, next_isempty); + width, pum_width, *totwidth_ptr, next_isempty, selected); if (attrs != NULL) VIM_CLEAR(attrs); diff --git a/src/testdir/dumps/Test_pum_maxwidth_23.dump b/src/testdir/dumps/Test_pum_maxwidth_23.dump new file mode 100644 index 000000000..aa8fafaa3 --- /dev/null +++ b/src/testdir/dumps/Test_pum_maxwidth_23.dump @@ -0,0 +1,8 @@ +|一*0&#ffffff0|二|三|四|五|六|七|八|九|十> +&@54 +|一*0#ff404010#e0e0e08|二|三|四|五|六|七| +&|>+0#0000001&| +0#4040ff13#ffffff0@58 +|1+0#ff404010#ffd7ff255|2|3|4|5|6|7|8|9|_|1|2|3|4|5|>+0#0000001&| +0#4040ff13#ffffff0@58 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim index f1fc9600c..1fd18ca4e 100644 --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -2030,6 +2030,7 @@ func Test_pum_maxwidth_multibyte() CheckScreendump let lines =<< trim END + hi StrikeFake ctermfg=9 let g:change = 0 func Omni_test(findstart, base) if a:findstart @@ -2054,8 +2055,14 @@ func Test_pum_maxwidth_multibyte() \ #{word: "bar", menu: "fooMenu", kind: "一二三四"}, \ #{word: "一二三四五", kind: "multi"}, \ ] - else 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 endfunc set omnifunc=Omni_test @@ -2168,6 +2175,12 @@ func Test_pum_maxwidth_multibyte() call term_sendkeys(buf, "\<Esc>:set norightleft\<CR>") 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) endfunc diff --git a/src/version.c b/src/version.c index 6e5b00c54..a63fc0929 100644 --- a/src/version.c +++ b/src/version.c @@ -709,6 +709,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1398, /**/ 1397, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1uGim2-0012un-UP%40256bit.org.