diff src/textprop.c @ 31489:966c87c57912 v9.0.1077

patch 9.0.1077: can add text property with negative ID before virtual text Commit: https://github.com/vim/vim/commit/4ce1f99a2d58b809ab5a5c602bd031426f8527e8 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 19 13:31:06 2022 +0000 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.
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Dec 2022 14:45:04 +0100
parents 243c35fad9cb
children 53c3df37a2b0
line wrap: on
line diff
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -424,6 +424,10 @@ get_textprop_id(buf_T *buf)
     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 @@ prop_add_common(
     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