]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0151: ml_get_buf_len() does not consider text properties v9.1.0151
authorChristian Brabandt <cb@256bit.org>
Tue, 5 Mar 2024 19:43:25 +0000 (20:43 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 5 Mar 2024 19:43:25 +0000 (20:43 +0100)
Problem:  ml_get_buf_len() does not consider text properties
          (zeertzj)
Solution: Store text length excluding text properties length
          in addition in the memline

related #14123
closes: #14133

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/change.c
src/edit.c
src/memline.c
src/structs.h
src/version.c

index 42e6f7939c0945e2fdadc70a63532912fc696b0d..847c1878364def5e7a581820bffb1dc4493d6c2d 100644 (file)
@@ -1364,6 +1364,7 @@ del_bytes(
            mch_memmove(newp + newlen + 1, oldp + oldlen + 1,
                               (size_t)curbuf->b_ml.ml_line_len - oldlen - 1);
        curbuf->b_ml.ml_line_len -= count;
+       curbuf->b_ml.ml_line_textlen = (int)STRLEN(newp) + 1;
     }
 #endif
 
index 5760b06e86680c6f5f0b00d8e466bcec85e73e84..d7c80ffcdf336989343ed4f9ccaafed0f8ada744 100644 (file)
@@ -5070,6 +5070,7 @@ ins_tab(void)
                        vim_free(curbuf->b_ml.ml_line_ptr);
                    curbuf->b_ml.ml_line_ptr = newp;
                    curbuf->b_ml.ml_line_len -= i;
+                   curbuf->b_ml.ml_line_textlen = (int)STRLEN(newp) + 1;
                    curbuf->b_ml.ml_flags =
                           (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
                }
index bbc13d7ed653ed2e196f931b35983c4fd20b74be..19d037f9eb77d32e6f0fd60b6f21e7b2b074cfd9 100644 (file)
@@ -2703,7 +2703,7 @@ ml_get_buf_len(buf_T *buf, linenr_T lnum)
     if (*ml_get_buf(buf, lnum, FALSE) == NUL)
         return 0;
 
-    return buf->b_ml.ml_line_len - 1;
+    return buf->b_ml.ml_line_textlen - 1;
 }
 
 /*
@@ -2737,6 +2737,7 @@ ml_get_buf(
 errorret:
        STRCPY(questions, "???");
        buf->b_ml.ml_line_len = 4;
+       buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
        buf->b_ml.ml_line_lnum = lnum;
        return questions;
     }
@@ -2746,6 +2747,7 @@ errorret:
     if (buf->b_ml.ml_mfp == NULL)      // there are no lines
     {
        buf->b_ml.ml_line_len = 1;
+       buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
        return (char_u *)"";
     }
 
@@ -2796,6 +2798,12 @@ errorret:
 
        buf->b_ml.ml_line_ptr = (char_u *)dp + start;
        buf->b_ml.ml_line_len = end - start;
+#if defined(FEAT_BYTEOFF) && defined(FEAT_PROP_POPUP)
+       if (buf->b_has_textprop)
+           buf->b_ml.ml_line_textlen = (int)STRLEN(buf->b_ml.ml_line_ptr) + 1;
+       else
+#endif
+           buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
        buf->b_ml.ml_line_lnum = lnum;
        buf->b_ml.ml_flags &= ~(ML_LINE_DIRTY | ML_ALLOCATED);
     }
@@ -3646,6 +3654,7 @@ ml_replace_len(
 
     curbuf->b_ml.ml_line_ptr = line;
     curbuf->b_ml.ml_line_len = len;
+    curbuf->b_ml.ml_line_textlen = len_arg + 1;
     curbuf->b_ml.ml_line_lnum = lnum;
     curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
 
index 2c6f553521945709f6e0f0113368fdaf3757f256..b3b3f6a144bcdc376b975b7b55b704a7f4104411 100644 (file)
@@ -802,7 +802,8 @@ typedef struct memline
 #define ML_ALLOCATED   0x10    // ml_line_ptr is an allocated copy
     int                ml_flags;
 
-    colnr_T    ml_line_len;    // length of the cached line, including NUL
+    colnr_T    ml_line_len;    // length of the cached line + textproperties, including NUL
+    colnr_T    ml_line_textlen;// length of the cached line, including NUL
     linenr_T   ml_line_lnum;   // line number of cached line, 0 if not valid
     char_u     *ml_line_ptr;   // pointer to cached line
 
index 8c48034e7ac2735750afbe7c2bf9641275c62a5c..ae5d17a1a8f26d5edeafa661511f3dcc31b4c54f 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    151,
 /**/
     150,
 /**/