Skip to content
forked from neovim/neovim

Commit

Permalink
Merge pull request neovim#19009 from neovim/backport-18820-to-release…
Browse files Browse the repository at this point in the history
…-0.7

[Backport release-0.7] fix(hl): backport neovim#18820, neovim#18981, neovim#18870
  • Loading branch information
clason committed Jun 18, 2022
2 parents 2ebc76b + 777d415 commit 30ae06c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/nvim/highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/nvim/highlight_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(= {
Expand Down Expand Up @@ -170,6 +171,7 @@ EXTERN const char *hlf_names[] INIT(= {
[HLF_NFLOAT] = "NormalFloat",
[HLF_MSG] = "MsgArea",
[HLF_BORDER] = "FloatBorder",
[HLF_CU] = "Cursor",
});


Expand Down
4 changes: 2 additions & 2 deletions src/nvim/highlight_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions test/functional/api/highlight_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion test/functional/ui/cursor_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30ae06c

Please sign in to comment.