changeset 30813:f4956427ee9e v9.0.0741

patch 9.0.0741: cannot specify an ID for each item with prop_add_list() Commit: https://github.com/vim/vim/commit/d93009eb35c88bfc38781fefdf42ebdb02c61474 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 13 14:35:24 2022 +0100 patch 9.0.0741: cannot specify an ID for each item with prop_add_list() Problem: Cannot specify an ID for each item with prop_add_list(). (Sergey Vlasov) Solution: Add an optional fifth number to the item. (closes #11360)
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Oct 2022 15:45:03 +0200
parents 19afe50858f8
children b3d8ec41adf1
files runtime/doc/textprop.txt src/testdir/test_textprop.vim src/textprop.c src/version.c
diffstat 4 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/doc/textprop.txt
+++ b/runtime/doc/textprop.txt
@@ -225,7 +225,7 @@ prop_add({lnum}, {col}, {props})
 			GetLnum()->prop_add(col, props)
 <
 						*prop_add_list()*
-prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
+prop_add_list({props}, [{item}, ...])
 		Similar to prop_add(), but attaches a text property at
 		multiple positions in a buffer.
 
@@ -237,12 +237,18 @@ prop_add_list({props}, [[{lnum}, {col}, 
 		   type		name of the text property type
 		All fields except "type" are optional.
 
-		The second argument is a List of Lists where each list
-		specifies the starting and ending position of the text.  The
-		first two items {lnum} and {col} specify the starting position
-		of the text where the property will be attached and the last
-		two items {end-lnum} and {end-col} specify the position just
-		after the text.
+		The second argument is a List of items, where each {item} is a
+		list that specifies the starting and ending position of the
+		text: [{lnum}, {col}, {end-lnum}, {end-col}]
+		or:   [{lnum}, {col}, {end-lnum}, {end-col}, {id}]
+
+		The first two items {lnum} and {col} specify the starting
+		position of the text where the property will be attached.
+		The next two items {end-lnum} and {end-col} specify the
+		position just after the text.
+		An optional fifth item {id} can be used to give a different ID
+		to a property.  When omitted the ID from {props} is used,
+		falling back to zero if none are present.
 
 		It is not possible to add a text property with a "text" field
 		here.
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -367,6 +367,16 @@ func Test_prop_add_list()
         \ length: 7, start: 1}], prop_list(3))
   call assert_equal([#{id: 2, col: 1, type_bufnr: 0, end: 1, type: 'one',
         \ length: 5, start: 0}], prop_list(4))
+  call prop_remove(#{id: 2})
+  call assert_equal([], prop_list(1))
+
+  call prop_add_list(#{type: 'one', id: 3},
+        \ [[1, 1, 1, 3], [2, 5, 2, 7, 9]])
+  call assert_equal([#{id: 3, col: 1, type_bufnr: 0, end: 1, type: 'one',
+        \ length: 2, start: 1}], prop_list(1))
+  call assert_equal([#{id: 9, col: 5, type_bufnr: 0, end: 1, type: 'one',
+        \ length: 2, start: 1}], prop_list(2))
+
   call assert_fails('call prop_add_list([1, 2], [[1, 1, 3]])', 'E1206:')
   call assert_fails('call prop_add_list({}, {})', 'E1211:')
   call assert_fails('call prop_add_list({}, [[1, 1, 3]])', 'E965:')
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -396,6 +396,9 @@ f_prop_add_list(typval_T *argvars, typva
 	    end_lnum = list_find_nr(pos_list, 2L, &error);
 	if (!error)
 	    end_col = list_find_nr(pos_list, 3L, &error);
+	int this_id = id;
+	if (!error && pos_list->lv_len > 4)
+	    this_id = list_find_nr(pos_list, 4L, &error);
 	if (error || start_lnum <= 0 || start_col <= 0
 		  || end_lnum <= 0 || end_col <= 0)
 	{
@@ -403,8 +406,8 @@ f_prop_add_list(typval_T *argvars, typva
 		emsg(_(e_invalid_argument));
 	    return;
 	}
-	if (prop_add_one(buf, type_name, id, NULL, 0, 0, start_lnum, end_lnum,
-						start_col, end_col) == FAIL)
+	if (prop_add_one(buf, type_name, this_id, NULL, 0, 0,
+			     start_lnum, end_lnum, start_col, end_col) == FAIL)
 	    return;
     }
 
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    741,
+/**/
     740,
 /**/
     739,