Skip to content

Commit 1615b36

Browse files
committed
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Problem: When setting the cterm background with ":hi Normal" the value of 'background' may be set wrongly. Solution: Check that the color is less than 16. Don't set 'background' when it was set explicitly. (Lemonboy, closes #1710)
1 parent bf15b8d commit 1615b36

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/syntax.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7834,18 +7834,25 @@ do_highlight(
78347834
must_redraw = CLEAR;
78357835
if (color >= 0)
78367836
{
7837+
int dark = -1;
7838+
78377839
if (termcap_active)
78387840
term_bg_color(color);
78397841
if (t_colors < 16)
7840-
i = (color == 0 || color == 4);
7841-
else
7842-
i = (color < 7 || color == 8);
7842+
dark = (color == 0 || color == 4);
7843+
/* Limit the heuristic to the standard 16 colors */
7844+
else if (color < 16)
7845+
dark = (color < 7 || color == 8);
78437846
/* Set the 'background' option if the value is
78447847
* wrong. */
7845-
if (i != (*p_bg == 'd'))
7848+
if (dark != -1
7849+
&& dark != (*p_bg == 'd')
7850+
&& !option_was_set((char_u *)"bg"))
7851+
{
78467852
set_option_value((char_u *)"bg", 0L,
7847-
i ? (char_u *)"dark"
7848-
: (char_u *)"light", 0);
7853+
(char_u *)(dark ? "dark" : "light"), 0);
7854+
reset_option_was_set((char_u *)"bg");
7855+
}
78497856
}
78507857
}
78517858
}

src/testdir/test_syntax.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,26 @@ func Test_highlight_invalid_arg()
401401
call assert_fails('hi XXX xxx=White', 'E423:')
402402
endfunc
403403

404+
func Test_bg_detection()
405+
if has('gui_running')
406+
return
407+
endif
408+
" auto-detection of &bg, make sure sure it isn't set anywhere before
409+
" this test
410+
hi Normal ctermbg=0
411+
call assert_equal('dark', &bg)
412+
hi Normal ctermbg=4
413+
call assert_equal('dark', &bg)
414+
hi Normal ctermbg=12
415+
call assert_equal('light', &bg)
416+
hi Normal ctermbg=15
417+
call assert_equal('light', &bg)
418+
419+
" manually-set &bg takes precendence over auto-detection
420+
set bg=light
421+
hi Normal ctermbg=4
422+
call assert_equal('light', &bg)
423+
set bg=dark
424+
hi Normal ctermbg=12
425+
call assert_equal('dark', &bg)
426+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
616,
767769
/**/
768770
615,
769771
/**/

0 commit comments

Comments
 (0)