To: vim_dev@googlegroups.com Subject: Patch 9.0.0741 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0741 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) Files: runtime/doc/textprop.txt, src/textprop.c, src/testdir/test_textprop.vim *** ../vim-9.0.0740/runtime/doc/textprop.txt 2022-09-10 20:00:31.117468669 +0100 --- runtime/doc/textprop.txt 2022-10-13 14:10:43.442417093 +0100 *************** *** 206,222 **** property with "text" has been added for a buffer then using a negative "id" for any other property will give an error: *E1293* - Make sure to use a highlight that makes clear to the user that - this is virtual text, otherwise it will be very confusing that - the text cannot be edited. - To separate the virtual text from the buffer text prepend - and/or append spaces to the "text" field. Can also be used as a |method|: > GetLnum()->prop_add(col, props) < *prop_add_list()* ! prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...]) Similar to prop_add(), but attaches a text property at multiple positions in a buffer. --- 223,234 ---- property with "text" has been added for a buffer then using a negative "id" for any other property will give an error: *E1293* Can also be used as a |method|: > GetLnum()->prop_add(col, props) < *prop_add_list()* ! prop_add_list({props}, [{item}, ...]) Similar to prop_add(), but attaches a text property at multiple positions in a buffer. *************** *** 228,239 **** 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. It is not possible to add a text property with a "text" field here. --- 240,257 ---- type name of the text property type All fields except "type" are optional. ! 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. *** ../vim-9.0.0740/src/textprop.c 2022-10-13 14:00:42.223235679 +0100 --- src/textprop.c 2022-10-13 14:12:54.998523119 +0100 *************** *** 396,401 **** --- 396,404 ---- 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,410 **** 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) return; } --- 406,413 ---- emsg(_(e_invalid_argument)); return; } ! if (prop_add_one(buf, type_name, this_id, NULL, 0, 0, ! start_lnum, end_lnum, start_col, end_col) == FAIL) return; } *** ../vim-9.0.0740/src/testdir/test_textprop.vim 2022-10-13 14:00:42.223235679 +0100 --- src/testdir/test_textprop.vim 2022-10-13 14:32:04.197874165 +0100 *************** *** 367,372 **** --- 367,382 ---- \ 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:') *** ../vim-9.0.0740/src/version.c 2022-10-13 14:00:42.223235679 +0100 --- src/version.c 2022-10-13 14:33:41.361765057 +0100 *************** *** 701,702 **** --- 701,704 ---- { /* Add new patch number below this line */ + /**/ + 741, /**/ -- There are 10 kinds of people: Those who understand binary and those who don't. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///