From 79ca64a1ef776d3f74d018b5ce6528fb8393a29b Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Wed, 1 Jun 2022 13:53:06 +1000 Subject: [PATCH 1/5] fix(hl): set Normal hl group sg_attr value (fixes #18024) (cherry picked from commit 03b4b07162386b2e5c3c9ef470476f02dce05115) --- src/nvim/highlight_group.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 3092aaefab..2c6cb06b52 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -743,6 +743,7 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id) normal_bg = g->sg_rgb_bg; normal_sp = g->sg_rgb_sp; ui_default_colors_set(); + g->sg_attr = hl_get_syn_attr(0, id, attrs); } else { g->sg_attr = hl_get_syn_attr(0, id, attrs); From 512a8197c84f990214e0f3bcfa0b8c100a9d36bd Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Thu, 2 Jun 2022 11:39:22 +1000 Subject: [PATCH 2/5] test(hl): Add Normal group set_hl/get_hl_by_name check (cherry picked from commit 02f70c163893d8602468bd061e2bf9b6280702e1) --- test/functional/api/highlight_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index a2f8353868..785f72b3db 100644 --- a/test/functional/api/highlight_spec.lua +++ b/test/functional/api/highlight_spec.lua @@ -337,4 +337,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) From ee210b0f749f68baae2ed5a8ce73bec7f601f5ca Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Thu, 2 Jun 2022 11:41:04 +1000 Subject: [PATCH 3/5] fix(hl): DRY set_hl_group() sg_attr set (cherry picked from commit 9747e984e1bb4820feb8fefbcf4df6ca84fbb47a) --- src/nvim/highlight_group.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 2c6cb06b52..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; @@ -743,10 +745,7 @@ void set_hl_group(int id, HlAttrs attrs, Dict(highlight) *dict, int link_id) normal_bg = g->sg_rgb_bg; normal_sp = g->sg_rgb_sp; ui_default_colors_set(); - g->sg_attr = hl_get_syn_attr(0, id, attrs); } 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(); From f70e0832b1cd820cc67d93985fb31a3788a7504d Mon Sep 17 00:00:00 2001 From: Oliver Marriott Date: Fri, 17 Jun 2022 11:33:58 +1000 Subject: [PATCH 4/5] fix(hl): return cterm fg/bg even if they match Normal #18981 Fixes #18980 - 831fa45ad84e 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 29bc6dfabde2 where it was avoiding setting a HL attr. But `hlattrs2dict()` now is just informational. --- src/nvim/highlight.c | 4 ++-- test/functional/api/highlight_spec.lua | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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/test/functional/api/highlight_spec.lua b/test/functional/api/highlight_spec.lua index 785f72b3db..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() From 777d415da886f4c9ee48bd8bed5f47d70f6b0737 Mon Sep 17 00:00:00 2001 From: zbirenbaum Date: Tue, 7 Jun 2022 01:54:04 -0400 Subject: [PATCH 5/5] fix(highlight): let winhighlight use cursor --- src/nvim/highlight_defs.h | 4 +++- test/functional/ui/cursor_spec.lua | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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/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