diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-12-02 20:46:26 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-12-02 20:46:26 +0000 |
commit | 89469d157aea01513bde826b4519dd6b5fbceae4 (patch) | |
tree | 50c505cfc7722e05f227d04f0ce8f4241b7b0448 /src/textprop.c | |
parent | 500c4442834363e02541da564f0b87b82d5783cd (diff) |
patch 9.0.0993: display errors when adding or removing text property typev9.0.0993
Problem: Display errors when adding or removing text property type.
Solution: Perform a full redraw. Only use text properties for which the
type is defined. (closes #11655)
Diffstat (limited to 'src/textprop.c')
-rw-r--r-- | src/textprop.c | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/textprop.c b/src/textprop.c index 789ab8ffe4..c1fc34e0ea 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -653,7 +653,7 @@ prop_count_above_below(buf_T *buf, linenr_T lnum) for (i = 0; i < count; ++i) { mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop)); - if (prop.tp_col == MAXCOL) + if (prop.tp_col == MAXCOL && text_prop_type_valid(buf, &prop)) { if ((prop.tp_flags & TP_FLAG_ALIGN_BELOW) || (next_right_goes_below @@ -697,7 +697,8 @@ count_props(linenr_T lnum, int only_starting, int last_line) // previous line, or when not in the last line and it is virtual text // after the line. if ((only_starting && (prop.tp_flags & TP_FLAG_CONT_PREV)) - || (!last_line && prop.tp_col == MAXCOL)) + || (!last_line && prop.tp_col == MAXCOL) + || !text_prop_type_valid(curbuf, &prop)) --result; } return result; @@ -801,20 +802,24 @@ sort_text_props( * Returns FAIL when not found. */ int -find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop, - linenr_T *found_lnum) +find_visible_prop( + win_T *wp, + int type_id, + int id, + textprop_T *prop, + linenr_T *found_lnum) { - linenr_T lnum; - char_u *props; - int count; - int i; + // return when "type_id" no longer exists + if (text_prop_type_by_id(wp->w_buffer, type_id) == NULL) + return FAIL; // w_botline may not have been updated yet. validate_botline_win(wp); - for (lnum = wp->w_topline; lnum < wp->w_botline; ++lnum) + for (linenr_T lnum = wp->w_topline; lnum < wp->w_botline; ++lnum) { - count = get_text_props(wp->w_buffer, lnum, &props, FALSE); - for (i = 0; i < count; ++i) + char_u *props; + int count = get_text_props(wp->w_buffer, lnum, &props, FALSE); + for (int i = 0; i < count; ++i) { mch_memmove(prop, props + i * sizeof(textprop_T), sizeof(textprop_T)); @@ -986,6 +991,15 @@ text_prop_type_by_id(buf_T *buf, int id) } /* + * Return TRUE if "prop" is a valid text property type. + */ + int +text_prop_type_valid(buf_T *buf, textprop_T *prop) +{ + return text_prop_type_by_id(buf, prop->tp_type) != NULL; +} + +/* * prop_clear({lnum} [, {lnum_end} [, {bufnr}]]) */ void @@ -1745,7 +1759,7 @@ prop_type_set(typval_T *argvars, int add) name = tv_get_string(&argvars[0]); if (*name == NUL) { - emsg(_(e_invalid_argument)); + semsg(_(e_invalid_argument_str), "\"\""); return; } @@ -1898,7 +1912,7 @@ f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED) name = tv_get_string(&argvars[0]); if (*name == NUL) { - emsg(_(e_invalid_argument)); + semsg(_(e_invalid_argument_str), "\"\""); return; } @@ -1926,6 +1940,10 @@ f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED) } hash_remove(ht, hi, "prop type delete"); vim_free(prop); + + // currently visibile text properties will disappear + redraw_all_later(UPD_CLEAR); + changed_window_setting_buf(buf == NULL ? curbuf : buf); } } @@ -1945,7 +1963,7 @@ f_prop_type_get(typval_T *argvars, typval_T *rettv) name = tv_get_string(&argvars[0]); if (*name == NUL) { - emsg(_(e_invalid_argument)); + semsg(_(e_invalid_argument_str), "\"\""); return; } if (rettv_dict_alloc(rettv) == OK) |