patch 9.0.1077: can add text property with negative ID before virtual text
Problem: Can add text property with negative ID before virtual text
property.
Solution: Remember that a text property with a negative ID was used and give
an appropriate error message. (closes #11725)
Fix index computation.
diff --git a/src/textprop.c b/src/textprop.c
index c1fc34e..a9778b5 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -424,6 +424,10 @@
return -(buf->b_textprop_text.ga_len + 1);
}
+// Flag that is set when a negative ID isused for a normal text property.
+// It is then impossible to use virtual text properties.
+static int did_use_negative_pop_id = FALSE;
+
/*
* Shared between prop_add() and popup_create().
* "dict_arg" is the function argument of a dict containing "bufnr".
@@ -576,13 +580,25 @@
if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL)
goto theend;
- if (id < 0 && buf->b_textprop_text.ga_len > 0)
+ if (id < 0)
{
- emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text));
- goto theend;
+ if (buf->b_textprop_text.ga_len > 0)
+ {
+ emsg(_(e_cannot_use_negative_id_after_adding_textprop_with_text));
+ goto theend;
+ }
+ did_use_negative_pop_id = TRUE;
}
+
if (text != NULL)
+ {
+ if (did_use_negative_pop_id)
+ {
+ emsg(_(e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id));
+ goto theend;
+ }
id = get_textprop_id(buf);
+ }
// This must be done _before_ we add the property because property changes
// trigger buffer (memline) reorganisation, which needs this flag to be