diff src/misc1.c @ 15138:9df130fd5e0d v8.1.0579

patch 8.1.0579: cannot attach properties to text commit https://github.com/vim/vim/commit/98aefe7c3250bb5d4153b994f878594d1745424e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 13 22:20:09 2018 +0100 patch 8.1.0579: cannot attach properties to text Problem: Cannot attach properties to text. Solution: First part of adding text properties.
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Dec 2018 22:30:08 +0100
parents 31a0127813cb
children d7a8f390f6d2
line wrap: on
line diff
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -2631,9 +2631,10 @@ del_bytes(
 {
     char_u	*oldp, *newp;
     colnr_T	oldlen;
+    colnr_T	newlen;
     linenr_T	lnum = curwin->w_cursor.lnum;
     colnr_T	col = curwin->w_cursor.col;
-    int		was_alloced;
+    int		alloc_newp;
     long	movelen;
     int		fixpos = fixpos_arg;
 
@@ -2710,6 +2711,7 @@ del_bytes(
 	count = oldlen - col;
 	movelen = 1;
     }
+    newlen = oldlen - count;
 
     /*
      * If the old line has been allocated the deletion can be done in the
@@ -2720,24 +2722,34 @@ del_bytes(
      */
 #ifdef FEAT_NETBEANS_INTG
     if (netbeans_active())
-	was_alloced = FALSE;
+	alloc_newp = TRUE;
     else
 #endif
-	was_alloced = ml_line_alloced();    /* check if oldp was allocated */
-    if (was_alloced)
-	newp = oldp;			    /* use same allocated memory */
+	alloc_newp = !ml_line_alloced();    // check if oldp was allocated
+    if (!alloc_newp)
+	newp = oldp;			    // use same allocated memory
     else
-    {					    /* need to allocate a new line */
-	newp = alloc((unsigned)(oldlen + 1 - count));
+    {					    // need to allocate a new line
+	newp = alloc((unsigned)(newlen + 1));
 	if (newp == NULL)
 	    return FAIL;
 	mch_memmove(newp, oldp, (size_t)col);
     }
     mch_memmove(newp + col, oldp + col + count, (size_t)movelen);
-    if (!was_alloced)
+    if (alloc_newp)
 	ml_replace(lnum, newp, FALSE);
-
-    /* mark the buffer as changed and prepare for displaying */
+#ifdef FEAT_TEXT_PROP
+    else
+    {
+	// Also move any following text properties.
+	if (oldlen + 1 < curbuf->b_ml.ml_line_len)
+	    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;
+    }
+#endif
+
+    // mark the buffer as changed and prepare for displaying
     changed_bytes(lnum, curwin->w_cursor.col);
 
     return OK;