From cb252071718a58c2d9747177ebeb81ff1210ddd1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 17 Jun 2019 22:35:07 +0200 Subject: vim-patch:8.0.0914: highlight attributes are always combined (#10256) Problem: Highlight attributes are always combined. Solution: Add the 'nocombine' value to replace attributes instead of combining them. (scauligi, closes vim/vim#1963) https://github.com/vim/vim/commit/0cd2a94a4030f6bd12eaec44db92db108e33c913 Closes https://github.com/neovim/neovim/pull/10256. --- src/nvim/highlight.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/nvim/highlight.c') diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 093cc4923b..83ee89b2a1 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -308,8 +308,16 @@ int hl_combine_attr(int char_attr, int prim_attr) // start with low-priority attribute, and override colors if present below. HlAttrs new_en = char_aep; - new_en.cterm_ae_attr |= spell_aep.cterm_ae_attr; - new_en.rgb_ae_attr |= spell_aep.rgb_ae_attr; + if (spell_aep.cterm_ae_attr & HL_NOCOMBINE) { + new_en.cterm_ae_attr = spell_aep.cterm_ae_attr; + } else { + new_en.cterm_ae_attr |= spell_aep.cterm_ae_attr; + } + if (spell_aep.rgb_ae_attr & HL_NOCOMBINE) { + new_en.rgb_ae_attr = spell_aep.rgb_ae_attr; + } else { + new_en.rgb_ae_attr |= spell_aep.rgb_ae_attr; + } if (spell_aep.cterm_fg_color > 0) { new_en.cterm_fg_color = spell_aep.cterm_fg_color; -- cgit From 08fe10010ab438451d976e8fb412c3034d9ffeed Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 11 Sep 2019 12:30:29 +0200 Subject: terminal: enable pass through indexed colors to TUI --- src/nvim/highlight.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/highlight.c') diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 83ee89b2a1..8564737ea2 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -611,6 +611,14 @@ Dictionary hlattrs2dict(HlAttrs ae, bool use_rgb) } if (use_rgb) { + if (mask & HL_FG_INDEXED) { + PUT(hl, "fg_indexed", BOOLEAN_OBJ(true)); + } + + if (mask & HL_BG_INDEXED) { + PUT(hl, "bg_indexed", BOOLEAN_OBJ(true)); + } + if (ae.rgb_fg_color != -1) { PUT(hl, "foreground", INTEGER_OBJ(ae.rgb_fg_color)); } -- cgit From 31137e9bc70f2514b065cc4b9beed42399ab2904 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 11 Sep 2019 19:11:18 +0200 Subject: highlight: correctly disable index attribute with combine/blend --- src/nvim/highlight.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/highlight.c') diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 8564737ea2..c96f07ed89 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -321,18 +321,26 @@ int hl_combine_attr(int char_attr, int prim_attr) if (spell_aep.cterm_fg_color > 0) { new_en.cterm_fg_color = spell_aep.cterm_fg_color; + new_en.rgb_ae_attr &= ((~HL_FG_INDEXED) + | (spell_aep.rgb_ae_attr & HL_FG_INDEXED)); } if (spell_aep.cterm_bg_color > 0) { new_en.cterm_bg_color = spell_aep.cterm_bg_color; + new_en.rgb_ae_attr &= ((~HL_BG_INDEXED) + | (spell_aep.rgb_ae_attr & HL_BG_INDEXED)); } if (spell_aep.rgb_fg_color >= 0) { new_en.rgb_fg_color = spell_aep.rgb_fg_color; + new_en.rgb_ae_attr &= ((~HL_FG_INDEXED) + | (spell_aep.rgb_ae_attr & HL_FG_INDEXED)); } if (spell_aep.rgb_bg_color >= 0) { new_en.rgb_bg_color = spell_aep.rgb_bg_color; + new_en.rgb_ae_attr &= ((~HL_BG_INDEXED) + | (spell_aep.rgb_ae_attr & HL_BG_INDEXED)); } if (spell_aep.rgb_sp_color >= 0) { @@ -422,6 +430,7 @@ int hl_blend_attrs(int back_attr, int front_attr, bool *through) cattrs.cterm_bg_color = fattrs.cterm_bg_color; cattrs.cterm_fg_color = cterm_blend(ratio, battrs.cterm_fg_color, fattrs.cterm_bg_color); + cattrs.rgb_ae_attr &= ~(HL_FG_INDEXED | HL_BG_INDEXED); } else { cattrs = fattrs; if (ratio >= 50) { @@ -435,6 +444,8 @@ int hl_blend_attrs(int back_attr, int front_attr, bool *through) } else { cattrs.rgb_sp_color = -1; } + + cattrs.rgb_ae_attr &= ~HL_BG_INDEXED; } cattrs.rgb_bg_color = rgb_blend(ratio, battrs.rgb_bg_color, fattrs.rgb_bg_color); -- cgit From 831fa45ad84e2f41730db3350289e660006139d6 Mon Sep 17 00:00:00 2001 From: kevinhwang91 Date: Wed, 8 Jan 2020 22:19:23 +0800 Subject: API: nvim_get_hl_by_id: omit hl instead of returning -1 #11685 Problem: When Normal highlight group defines ctermfg/bg, but other highlight group lacks ctermfg/bg, nvim_get_hl_by_id(hl_id, v:false) returns -1 for the missing ctermfg/bg instead of just omitting it. Solution: checking for -1 in hlattrs2dict() fix #11680 --- src/nvim/highlight.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/highlight.c') diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index c96f07ed89..c0cae54572 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -642,11 +642,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) { + if (cterm_normal_fg_color != ae.cterm_fg_color && ae.cterm_fg_color != 0) { PUT(hl, "foreground", INTEGER_OBJ(ae.cterm_fg_color - 1)); } - if (cterm_normal_bg_color != ae.cterm_bg_color) { + if (cterm_normal_bg_color != ae.cterm_bg_color && ae.cterm_bg_color != 0) { PUT(hl, "background", INTEGER_OBJ(ae.cterm_bg_color - 1)); } } -- cgit From 872ecf65d10f0d22bbf3e2257f9ae89a6c61d2f4 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 1 Aug 2020 01:52:15 +0900 Subject: ui: fix problem with sattr_T overflow sattr_T was defined as uint16_t. But this is not enough to handle the 24-bit colors of the terminal. To solve this problem, change it to int. In 32bit, int may overflow. So, if it overflows, change it to ignore it without adding more attr_entries. fixes #12366 --- src/nvim/highlight.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/highlight.c') diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index c0cae54572..262afba07a 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -90,7 +90,12 @@ static int get_attr_entry(HlEntry entry) } } - id = (int)kv_size(attr_entries); + size_t next_id = kv_size(attr_entries); + if (next_id > INT_MAX) { + ELOG("The index on attr_entries has overflowed"); + return 0; + } + id = (int)next_id; kv_push(attr_entries, entry); map_put(HlEntry, int)(attr_entry_ids, entry, id); -- cgit