fix(hl): return cterm fg/bg even if they match Normal #18981

Fixes #18980

- 831fa45ad8 is related but this doesn't regress that
- The `cterm_normal_fg_color != ae.cterm_fg_color` comparison is originally
  carried from patch to patch starting all the way back in 29bc6dfabd where it
  was avoiding setting a HL attr. But `hlattrs2dict()` now is just
  informational.
This commit is contained in:
Oliver Marriott 2022-06-17 11:33:58 +10:00 committed by GitHub
parent e0aa1d87e8
commit 98e2da7d50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -792,11 +792,11 @@ Dictionary hlattrs2dict(HlAttrs ae, bool use_rgb)
PUT(hl, "special", INTEGER_OBJ(ae.rgb_sp_color)); PUT(hl, "special", INTEGER_OBJ(ae.rgb_sp_color));
} }
} else { } else {
if (cterm_normal_fg_color != ae.cterm_fg_color && ae.cterm_fg_color != 0) { if (ae.cterm_fg_color != 0) {
PUT(hl, "foreground", INTEGER_OBJ(ae.cterm_fg_color - 1)); PUT(hl, "foreground", INTEGER_OBJ(ae.cterm_fg_color - 1));
} }
if (cterm_normal_bg_color != ae.cterm_bg_color && ae.cterm_bg_color != 0) { if (ae.cterm_bg_color != 0) {
PUT(hl, "background", INTEGER_OBJ(ae.cterm_bg_color - 1)); PUT(hl, "background", INTEGER_OBJ(ae.cterm_bg_color - 1));
} }
} }

View File

@ -133,6 +133,13 @@ describe('API: highlight',function()
eq({ underline = true, standout = true, }, eq({ underline = true, standout = true, },
meths.get_hl_by_name('cursorline', 0)); meths.get_hl_by_name('cursorline', 0));
-- Test cterm & Normal values. #18024 (tail) & #18980
-- Ensure Normal, and groups that match Normal return their fg & bg cterm values
meths.set_hl(0, 'Normal', {ctermfg = 17, ctermbg = 213})
meths.set_hl(0, 'NotNormal', {ctermfg = 17, ctermbg = 213})
-- Note colors are "cterm" values, not rgb-as-ints
eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'Normal', false))
eq({foreground = 17, background = 213}, nvim("get_hl_by_name", 'NotNormal', false))
end) end)
it('nvim_get_hl_id_by_name', function() it('nvim_get_hl_id_by_name', function()