]> granicus.if.org Git - vim/commitdiff
patch 8.2.3372: line2byte() value wrong when adding a text property v8.2.3372
authorBram Moolenaar <Bram@vim.org>
Wed, 25 Aug 2021 14:40:03 +0000 (16:40 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 25 Aug 2021 14:40:03 +0000 (16:40 +0200)
Problem:    line2byte() value wrong when adding a text property. (Yuto Kimura)
Solution:   Adjust length for text property. (closes #8772)  Also fix it for
            deleting a line.

src/memline.c
src/testdir/test_textprop.vim
src/version.c

index 5aeee900f21c2b3b2f595939b9ece14377d9d396..2192036ed998f7aa186ea7e1d3924b9e9acc1f13 100644 (file)
@@ -3251,9 +3251,15 @@ ml_append_int(
     }
 
 #ifdef FEAT_BYTEOFF
+# ifdef FEAT_PROP_POPUP
+    if (curbuf->b_has_textprop)
+       // only use the space needed for the text, ignore properties
+       len = (colnr_T)STRLEN(line) + 1;
+# endif
     // The line was inserted below 'lnum'
     ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE);
 #endif
+
 #ifdef FEAT_NETBEANS_INTG
     if (netbeans_active())
     {
@@ -3752,7 +3758,11 @@ ml_delete_int(buf_T *buf, linenr_T lnum, int flags)
     }
 
 #ifdef FEAT_BYTEOFF
-    ml_updatechunk(buf, lnum, line_size, ML_CHNK_DELLINE);
+    ml_updatechunk(buf, lnum, line_size
+# ifdef FEAT_PROP_POPUP
+                                       - textprop_save_len
+# endif
+                                                           , ML_CHNK_DELLINE);
 #endif
     ret = OK;
 
index 373df6e6530438fe0a8e56f2d0ca55f87e7b0bbd..f21fd40488ed1603b797dc298c3ee1bdeb6480c8 100644 (file)
@@ -857,6 +857,15 @@ func Test_prop_line2byte()
   call assert_equal(1491, line2byte(401))
   bwipe!
 
+  new
+  call setline(1, range(520))
+  call assert_equal(1491, line2byte(401))
+  call prop_add(2, 1, {'type': 'comment'})
+  call assert_equal(1491, line2byte(401))
+  2delete
+  call assert_equal(1489, line2byte(400))
+  bwipe!
+
   call prop_type_delete('comment')
 endfunc
 
index 6e7dd93cbf10169ef4214d1682f81e3fa08c7aae..1f9a2701605f38bcdeee0eaeaeaf221d3c04f1dc 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3372,
 /**/
     3371,
 /**/