diff src/textprop.c @ 16811:0457d49eb2d9 v8.1.1407

patch 8.1.1407: popup_create() does not support text properties commit https://github.com/vim/vim/commit/7a8d0278bd6bd57e04f61183cb8e2969cf148e3f Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 26 23:32:06 2019 +0200 patch 8.1.1407: popup_create() does not support text properties Problem: Popup_create() does not support text properties. Solution: Support the third form of the text argument.
author Bram Moolenaar <Bram@vim.org>
date Sun, 26 May 2019 23:45:05 +0200
parents fc58fee685e2
children ce04ebdf26b8
line wrap: on
line diff
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -142,23 +142,8 @@ get_bufnr_from_arg(typval_T *arg, buf_T 
     void
 f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
 {
-    linenr_T	lnum;
     linenr_T	start_lnum;
-    linenr_T	end_lnum;
     colnr_T	start_col;
-    colnr_T	end_col;
-    dict_T	*dict;
-    char_u	*type_name;
-    proptype_T	*type;
-    buf_T	*buf = curbuf;
-    int		id = 0;
-    char_u	*newtext;
-    int		proplen;
-    size_t	textlen;
-    char_u	*props = NULL;
-    char_u	*newprops;
-    textprop_T	tmp_prop;
-    int		i;
 
     start_lnum = tv_get_number(&argvars[0]);
     start_col = tv_get_number(&argvars[1]);
@@ -172,7 +157,38 @@ f_prop_add(typval_T *argvars, typval_T *
 	emsg(_(e_dictreq));
 	return;
     }
-    dict = argvars[2].vval.v_dict;
+
+    prop_add_common(start_lnum, start_col, argvars[2].vval.v_dict,
+							  curbuf, &argvars[2]);
+}
+
+/*
+ * Shared between prop_add() and popup_create().
+ * "dict_arg" is the function argument of a dict containing "bufnr".
+ * it is NULL for popup_create().
+ */
+    void
+prop_add_common(
+	linenr_T    start_lnum,
+	colnr_T	    start_col,
+	dict_T	    *dict,
+	buf_T	    *default_buf,
+	typval_T    *dict_arg)
+{
+    linenr_T	lnum;
+    linenr_T	end_lnum;
+    colnr_T	end_col;
+    char_u	*type_name;
+    proptype_T	*type;
+    buf_T	*buf = default_buf;
+    int		id = 0;
+    char_u	*newtext;
+    int		proplen;
+    size_t	textlen;
+    char_u	*props = NULL;
+    char_u	*newprops;
+    textprop_T	tmp_prop;
+    int		i;
 
     if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL)
     {
@@ -221,7 +237,7 @@ f_prop_add(typval_T *argvars, typval_T *
     if (dict_find(dict, (char_u *)"id", -1) != NULL)
 	id = dict_get_number(dict, (char_u *)"id");
 
-    if (get_bufnr_from_arg(&argvars[2], &buf) == FAIL)
+    if (dict_arg != NULL && get_bufnr_from_arg(dict_arg, &buf) == FAIL)
 	return;
 
     type = lookup_prop_type(type_name, buf);
@@ -278,12 +294,12 @@ f_prop_add(typval_T *argvars, typval_T *
 	mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen);
 
 	// Find the index where to insert the new property.
-	// Since the text properties are not aligned properly when stored with the
-	// text, we need to copy them as bytes before using it as a struct.
+	// Since the text properties are not aligned properly when stored with
+	// the text, we need to copy them as bytes before using it as a struct.
 	for (i = 0; i < proplen; ++i)
 	{
 	    mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
-							       sizeof(textprop_T));
+							   sizeof(textprop_T));
 	    if (tmp_prop.tp_col >= col)
 		break;
 	}
@@ -298,7 +314,7 @@ f_prop_add(typval_T *argvars, typval_T *
 	tmp_prop.tp_flags = (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0)
 			  | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0);
 	mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop,
-							       sizeof(textprop_T));
+							   sizeof(textprop_T));
 
 	if (i < proplen)
 	    mch_memmove(newprops + (i + 1) * sizeof(textprop_T),