diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 7d91f38d56..6c1f314339 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -794,11 +794,11 @@ Dictionary hlattrs2dict(HlAttrs ae, bool use_rgb) PUT(hl, "special", INTEGER_OBJ(ae.rgb_sp_color)); } } 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)); } - 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)); } } diff --git a/src/nvim/highlight_defs.h b/src/nvim/highlight_defs.h index e0ee649013..0cbc3454be 100644 --- a/src/nvim/highlight_defs.h +++ b/src/nvim/highlight_defs.h @@ -110,7 +110,8 @@ typedef enum { HLF_NFLOAT, // Floating window HLF_MSG, // Message area HLF_BORDER, // Floating window border - HLF_COUNT, // MUST be the last one + HLF_CU, // Cursor + HLF_COUNT, // MUST be the last one } hlf_T; EXTERN const char *hlf_names[] INIT(= { @@ -170,6 +171,7 @@ EXTERN const char *hlf_names[] INIT(= { [HLF_NFLOAT] = "NormalFloat", [HLF_MSG] = "MsgArea", [HLF_BORDER] = "FloatBorder", + [HLF_CU] = "Cursor", }); diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 3092aaefab..7408fbfdc1 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -735,6 +735,8 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id) g->sg_script_ctx = current_sctx; g->sg_script_ctx.sc_lnum += sourcing_lnum; + g->sg_attr = hl_get_syn_attr(0, id, attrs); + // 'Normal' is special if (STRCMP(g->sg_name_u, "NORMAL") == 0) { cterm_normal_fg_color = g->sg_cterm_fg; @@ -744,8 +746,6 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id) normal_sp = g->sg_rgb_sp; ui_default_colors_set(); } else { - g->sg_attr = hl_get_syn_attr(0, id, attrs); - // a cursor style uses this syn_id, make sure its attribute is updated. if (cursor_mode_uses_syn_id(id)) { ui_mode_info_set(); diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a2f8353868..8235374f22 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -133,6 +133,13 @@ describe('API: highlight',function() eq({ underline = true, standout = true, }, 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) it('nvim_get_hl_id_by_name', function() @@ -337,4 +344,10 @@ describe("API: set highlight", function() exec_capture('highlight Test_hl3')) end) + + it ("correctly sets 'Normal' internal properties", function() + -- Normal has some special handling internally. #18024 + meths.set_hl(0, 'Normal', {fg='#000083', bg='#0000F3'}) + eq({foreground = 131, background = 243}, nvim("get_hl_by_name", 'Normal', true)) + end) end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 4c51547e2c..121fe182ef 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -212,7 +212,7 @@ describe('ui/cursor', function() if m.blinkwait then m.blinkwait = 700 end end if m.hl_id then - m.hl_id = 61 + m.hl_id = 57 m.attr = {background = Screen.colors.DarkGray} end if m.id_lm then m.id_lm = 62 end