Skip to content

Commit 9b41e8f

Browse files
ychinchrisbra
authored andcommitted
patch 9.1.1150: :hi completion may complete to wrong value
Problem: :highlight auto-complettion has a minor bug where an existing highlight group with a cterm color being unset would result in it being auto-completed to -1 in cmdline which is invalid. Solution: Correctly check for whether an int value is set to non-zero before retrieving the existing value for auto-complete. Also do this for attr/string values as they previously worked only by accident (Yee Cheng Chin). closes: #16726 Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent aa8345a commit 9b41e8f

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/highlight.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,14 +4531,17 @@ expand_highlight_group(
45314531

45324532
char_u buf[MAX_ATTR_LEN];
45334533

4534-
if (expand_hi_synid != 0 && type != 0 && expand_hi_include_orig)
4534+
expand_hi_curvalue = NULL;
4535+
if (expand_hi_include_orig)
45354536
{
4536-
// Retrieve the current value to go first in completion
4537-
expand_hi_curvalue = highlight_arg_to_string(
4538-
type, iarg, sarg, buf);
4537+
if (((type == LIST_ATTR || type == LIST_INT) && iarg != 0) ||
4538+
(type == LIST_STRING && sarg != NULL))
4539+
{
4540+
// Retrieve the current value to go first in completion
4541+
expand_hi_curvalue = highlight_arg_to_string(
4542+
type, iarg, sarg, buf);
4543+
}
45394544
}
4540-
else
4541-
expand_hi_curvalue = NULL;
45424545

45434546
if (expandfunc != NULL)
45444547
{

src/testdir/test_cmdline.vim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,22 @@ func Test_highlight_group_completion()
488488

489489
" Test completing the current value
490490
hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34
491+
hi AlmostEmpty term=bold
491492
call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0])
492493
call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0])
493494
call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0])
494495
call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0])
495496
call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0])
496497

497-
" "bold,underline" is unique and creates an extra item. "undercurl" and
498-
" should be de-duplicated
498+
" highlight group exists, but no value was set. Should not complete to
499+
" existing value
500+
call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0])
501+
call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0])
502+
call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0])
503+
call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0])
504+
505+
" "bold,underline" is unique and creates an extra item. "undercurl" isn't
506+
" and should be de-duplicated.
499507
call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')),
500508
\ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline')))
501509

@@ -519,6 +527,13 @@ func Test_highlight_group_completion()
519527

520528
" Check that existing value is de-duplicated and doesn't show up later
521529
call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1'))
530+
531+
" highlight group exists, but no value was set. Should not complete to
532+
" existing value
533+
call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0])
534+
call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0])
535+
call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0])
536+
call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0])
522537
endif
523538

524539
" Test completing attributes

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1150,
707709
/**/
708710
1149,
709711
/**/

0 commit comments

Comments
 (0)