diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/cursor_shape.c | 24 | ||||
-rw-r--r-- | src/nvim/syntax.c | 7 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 14 | ||||
-rw-r--r-- | src/nvim/ui.c | 13 |
4 files changed, 41 insertions, 17 deletions
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index b45e7002f7..cf79005a37 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -64,6 +64,9 @@ Array mode_style_array(void) PUT(dic, "blinkoff", INTEGER_OBJ(cur->blinkoff)); PUT(dic, "hl_id", INTEGER_OBJ(cur->id)); PUT(dic, "id_lm", INTEGER_OBJ(cur->id_lm)); + PUT(dic, "attr_id", INTEGER_OBJ(cur->id ? syn_id2attr(cur->id) : 0)); + PUT(dic, "attr_id_lm", INTEGER_OBJ(cur->id_lm ? syn_id2attr(cur->id_lm) + : 0)); } PUT(dic, "name", STRING_OBJ(cstr_to_string(cur->full_name))); PUT(dic, "short_name", STRING_OBJ(cstr_to_string(cur->name))); @@ -258,15 +261,30 @@ char_u *parse_shape_opt(int what) /// @return -1 in case of failure, else the matching SHAPE_ID* integer int cursor_mode_str2int(const char *mode) { - for (int current_mode = 0; current_mode < SHAPE_IDX_COUNT; current_mode++) { - if (strcmp(shape_table[current_mode].full_name, mode) == 0) { - return current_mode; + for (int mode_idx = 0; mode_idx < SHAPE_IDX_COUNT; mode_idx++) { + if (strcmp(shape_table[mode_idx].full_name, mode) == 0) { + return mode_idx; } } WLOG("Unknown mode %s", mode); return -1; } +/// Check if a syntax id is used as a cursor style. +bool cursor_mode_uses_syn_id(int syn_id) +{ + if (*p_guicursor == NUL) { + return false; + } + for (int mode_idx = 0; mode_idx < SHAPE_IDX_COUNT; mode_idx++) { + if (shape_table[mode_idx].id == syn_id + || shape_table[mode_idx].id_lm == syn_id) { + return true; + } + } + return false; +} + /// Return the index into shape_table[] for the current mode. int cursor_get_mode_idx(void) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d7c23742ba..3cb998b805 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -16,6 +16,7 @@ #include "nvim/ascii.h" #include "nvim/syntax.h" #include "nvim/charset.h" +#include "nvim/cursor_shape.h" #include "nvim/eval.h" #include "nvim/ex_cmds2.h" #include "nvim/ex_docmd.h" @@ -7228,7 +7229,6 @@ static void set_hl_attr(int idx) HlAttrs at_en = HLATTRS_INIT; struct hl_group *sgp = HL_TABLE() + idx; - at_en.cterm_ae_attr = sgp->sg_cterm; at_en.cterm_fg_color = sgp->sg_cterm_fg; at_en.cterm_bg_color = sgp->sg_cterm_bg; @@ -7241,6 +7241,11 @@ static void set_hl_attr(int idx) at_en.rgb_sp_color = sgp->sg_rgb_sp_name ? sgp->sg_rgb_sp : -1; sgp->sg_attr = hl_get_syn_attr(idx+1, at_en); + + // a cursor style uses this syn_id, make sure its atribute is updated. + if (cursor_mode_uses_syn_id(idx+1)) { + ui_mode_info_set(); + } } /// Lookup a highlight group name and return its ID. diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index c010f2e1a2..df14ddf988 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -874,7 +874,7 @@ static cursorentry_T decode_cursor_entry(Dictionary args) r.blinkon = (int)value.data.integer; } else if (strequal(key, "blinkoff")) { r.blinkoff = (int)value.data.integer; - } else if (strequal(key, "hl_id")) { + } else if (strequal(key, "attr_id")) { r.id = (int)value.data.integer; } } @@ -942,14 +942,10 @@ static void tui_set_mode(UI *ui, ModeShape mode) TUIData *data = ui->data; cursorentry_T c = data->cursor_shapes[mode]; - if (c.id != 0 && ui->rgb) { - // TODO(bfredl): NOT threadsafe, include attr in cursor_shape already. - int attr = syn_id2attr(c.id); - if (attr > 0 && attr < (int)kv_size(data->attrs)) { - int color = kv_A(data->attrs, attr).rgb_bg_color; - UNIBI_SET_NUM_VAR(data->params[0], color); - unibi_out_ext(ui, data->unibi_ext.set_cursor_color); - } + if (c.id != 0 && c.id < (int)kv_size(data->attrs) && ui->rgb) { + int color = kv_A(data->attrs, c.id).rgb_bg_color; + UNIBI_SET_NUM_VAR(data->params[0], color); + unibi_out_ext(ui, data->unibi_ext.set_cursor_color); } int shape; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index ef68b804ba..07aa032a50 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -55,6 +55,7 @@ static int row = 0, col = 0; static bool pending_cursor_update = false; static int busy = 0; static int mode_idx = SHAPE_IDX_N; +static bool pending_mode_info_update = false; static bool pending_mode_update = false; #if MIN_LOG_LEVEL > DEBUG_LOG_LEVEL @@ -368,10 +369,7 @@ void ui_add_linewrap(int row) void ui_mode_info_set(void) { - Array style = mode_style_array(); - bool enabled = (*p_guicursor != NUL); - ui_call_mode_info_set(enabled, style); - api_free_array(style); + pending_mode_info_update = true; } int ui_current_row(void) @@ -391,6 +389,13 @@ void ui_flush(void) ui_call_grid_cursor_goto(1, row, col); pending_cursor_update = false; } + if (pending_mode_info_update) { + Array style = mode_style_array(); + bool enabled = (*p_guicursor != NUL); + ui_call_mode_info_set(enabled, style); + api_free_array(style); + pending_mode_info_update = false; + } if (pending_mode_update) { char *full_name = shape_table[mode_idx].full_name; ui_call_mode_change(cstr_as_string(full_name), mode_idx); |