patch 8.1.0579: cannot attach properties to text
Problem: Cannot attach properties to text.
Solution: First part of adding text properties.
diff --git a/src/misc1.c b/src/misc1.c
index f1f0074..40d6f93 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -2631,9 +2631,10 @@
{
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 @@
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 @@
*/
#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);
+#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 */
+ // mark the buffer as changed and prepare for displaying
changed_bytes(lnum, curwin->w_cursor.col);
return OK;