Merge pull request #19009 from neovim/backport-18820-to-release-0.7

[Backport release-0.7] fix(hl): backport #18820, #18981, #18870
This commit is contained in:
Christian Clason
2022-06-18 15:03:56 +02:00
committed by GitHub
5 changed files with 21 additions and 6 deletions

View File

@ -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));
}
}

View File

@ -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",
});

View File

@ -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();

View File

@ -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)

View File

@ -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