0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 9.0.0993: display errors when adding or removing text property type

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)
This commit is contained in:
Bram Moolenaar
2022-12-02 20:46:26 +00:00
parent 500c444283
commit 89469d157a
11 changed files with 126 additions and 18 deletions

View File

@@ -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));
@@ -985,6 +990,15 @@ text_prop_type_by_id(buf_T *buf, int id)
return type;
}
/*
* 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}]])
*/
@@ -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)