summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2026-04-20 17:12:52 +0800
committerGitHub <noreply@github.com>2026-04-20 05:12:52 -0400
commit01861c2f955119cc88158273e100b3490c3df6e1 (patch)
tree3f50ea711837fa84ecdc1254dce7cc46fda761bc /src
parentc7d4892ce6615e83113035823979cf424f0c12f5 (diff)
fix(api): expose fg_indexed/bg_indexed in nvim_get_hl #39210
Problem: fg_indexed/bg_indexed were dropped from nvim_get_hl output due to a wrong short_keys guard. HL_FG_INDEXED also wasn't cleared in hl_blend_attrs, and HLATTRS_DICT_SIZE was too small. Solution: Remove the short_keys guard, clear HL_FG_INDEXED in hl_blend_attrs, bump HLATTRS_DICT_SIZE to 24, and clarify docs that these flags mean rgb is an approximation of the cterm palette index.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/vim.c5
-rw-r--r--src/nvim/highlight.c18
-rw-r--r--src/nvim/highlight_defs.h2
3 files changed, 12 insertions, 13 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index aa3475ad76..9adc4914a8 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -144,7 +144,8 @@ DictAs(get_hl_info) nvim_get_hl(Integer ns_id, Dict(get_highlight) *opts, Arena
/// @param val Highlight definition map, accepts the following keys:
/// - altfont: boolean
/// - bg: color name or "#RRGGBB", see note.
-/// - bg_indexed: boolean (default false) If true, bg is a terminal palette index (0-255).
+/// - bg_indexed: boolean. If true, `bg` is an RGB approximation of `ctermbg`
+/// (a palette index). UIs rendering cterm natively may prefer `ctermbg`.
/// - blend: integer between 0 and 100
/// - blink: boolean
/// - bold: boolean
@@ -156,7 +157,7 @@ DictAs(get_hl_info) nvim_get_hl(Integer ns_id, Dict(get_highlight) *opts, Arena
/// - default: boolean Don't override existing definition |:hi-default|
/// - dim: boolean
/// - fg: Color name or "#RRGGBB", see note.
-/// - fg_indexed: boolean (default false) If true, fg is a terminal palette index (0-255).
+/// - fg_indexed: boolean. Same as `bg_indexed`, for `fg` and `ctermfg`.
/// - font: GUI font name (string). Sets |highlight-font|. Use "NONE" to clear.
/// - force: boolean (default false) Update the highlight group even if it already exists.
/// - italic: boolean
diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c
index be58fd9fc4..1d2bb3afd2 100644
--- a/src/nvim/highlight.c
+++ b/src/nvim/highlight.c
@@ -797,7 +797,7 @@ int hl_blend_attrs(int back_attr, int front_attr, bool *through)
cattrs.rgb_sp_color = -1;
}
- cattrs.rgb_ae_attr &= ~HL_BG_INDEXED;
+ cattrs.rgb_ae_attr &= ~(HL_FG_INDEXED | HL_BG_INDEXED);
}
// Check if we should preserve background transparency
@@ -956,8 +956,8 @@ Dict hl_get_attr_by_id(Integer attr_id, Boolean rgb, Arena *arena, Error *err)
void hlattrs2dict(Dict *hl, Dict *hl_attrs, HlAttrs ae, bool use_rgb, bool short_keys)
{
hl_attrs = hl_attrs ? hl_attrs : hl;
- assert(hl->capacity >= HLATTRS_DICT_SIZE); // at most 16 items
- assert(hl_attrs->capacity >= HLATTRS_DICT_SIZE); // at most 16 items
+ assert(hl->capacity >= HLATTRS_DICT_SIZE); // at most 24 items
+ assert(hl_attrs->capacity >= HLATTRS_DICT_SIZE); // at most 24 items
int mask = use_rgb ? ae.rgb_ae_attr : ae.cterm_ae_attr;
if (mask & HL_INVERSE) {
@@ -1039,14 +1039,12 @@ void hlattrs2dict(Dict *hl, Dict *hl_attrs, HlAttrs ae, bool use_rgb, bool short
PUT_C(*hl, short_keys ? "sp" : "special", INTEGER_OBJ(ae.rgb_sp_color));
}
- if (!short_keys) {
- if (mask & HL_FG_INDEXED) {
- PUT_C(*hl, "fg_indexed", BOOLEAN_OBJ(true));
- }
+ if (mask & HL_FG_INDEXED) {
+ PUT_C(*hl, "fg_indexed", BOOLEAN_OBJ(true));
+ }
- if (mask & HL_BG_INDEXED) {
- PUT_C(*hl, "bg_indexed", BOOLEAN_OBJ(true));
- }
+ if (mask & HL_BG_INDEXED) {
+ PUT_C(*hl, "bg_indexed", BOOLEAN_OBJ(true));
}
} else {
if (ae.cterm_fg_color != 0) {
diff --git a/src/nvim/highlight_defs.h b/src/nvim/highlight_defs.h
index b682105196..0460fbb829 100644
--- a/src/nvim/highlight_defs.h
+++ b/src/nvim/highlight_defs.h
@@ -181,4 +181,4 @@ typedef struct {
#define COLOR_ITEM_INITIALIZER { .attr_id = -1, .link_id = -1, .version = -1, \
.is_default = false, .link_global = false }
-enum { HLATTRS_DICT_SIZE = 20, };
+enum { HLATTRS_DICT_SIZE = 24, };