aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/highlight.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/highlight.c')
-rw-r--r--src/nvim/highlight.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c
index 093cc4923b..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);
@@ -308,23 +313,39 @@ 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;
+ 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) {
@@ -414,6 +435,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) {
@@ -427,6 +449,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);
@@ -603,6 +627,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));
}
@@ -615,11 +647,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));
}
}