diff src/misc1.c @ 15341:03a7a9fdb792 v8.1.0678

patch 8.1.0678: text properties as not adjusted for inserted text commit https://github.com/vim/vim/commit/44746aa1eb506ebe6e8fc71f6e549a0dcb754526 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 2 00:02:11 2019 +0100 patch 8.1.0678: text properties as not adjusted for inserted text Problem: Text properties as not adjusted for inserted text. Solution: Adjust text properties when inserting text.
author Bram Moolenaar <Bram@vim.org>
date Wed, 02 Jan 2019 00:15:05 +0100
parents fe428bee74b3
children f6b522596993
line wrap: on
line diff
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -2322,7 +2322,7 @@ ins_bytes_len(char_u *p, int len)
 	for (i = 0; i < len; i += n)
 	{
 	    if (enc_utf8)
-		/* avoid reading past p[len] */
+		// avoid reading past p[len]
 		n = utfc_ptr2len_len(p + i, len - i);
 	    else
 		n = (*mb_ptr2len)(p + i);
@@ -2365,12 +2365,12 @@ ins_char(int c)
 ins_char_bytes(char_u *buf, int charlen)
 {
     int		c = buf[0];
-    int		newlen;		/* nr of bytes inserted */
-    int		oldlen;		/* nr of bytes deleted (0 when not replacing) */
+    int		newlen;		// nr of bytes inserted
+    int		oldlen;		// nr of bytes deleted (0 when not replacing)
     char_u	*p;
     char_u	*newp;
     char_u	*oldp;
-    int		linelen;	/* length of old line including NUL */
+    int		linelen;	// length of old line including NUL
     colnr_T	col;
     linenr_T	lnum = curwin->w_cursor.lnum;
     int		i;
@@ -2439,8 +2439,7 @@ ins_char_bytes(char_u *buf, int charlen)
 	    }
 	    curwin->w_p_list = old_list;
 	}
-	else
-	    if (oldp[col] != NUL)
+	else if (oldp[col] != NUL)
 	{
 	    /* normal replace */
 #ifdef FEAT_MBYTE
@@ -2494,11 +2493,11 @@ ins_char_bytes(char_u *buf, int charlen)
     while (i < newlen)
 	p[i++] = ' ';
 
-    /* Replace the line in the buffer. */
+    // Replace the line in the buffer.
     ml_replace(lnum, newp, FALSE);
 
-    /* mark the buffer as changed and prepare for displaying */
-    changed_bytes(lnum, col);
+    // mark the buffer as changed and prepare for displaying
+    inserted_bytes(lnum, col, newlen - oldlen);
 
     /*
      * If we're in Insert or Replace mode and 'showmatch' is set, then briefly
@@ -2566,7 +2565,7 @@ ins_str(char_u *s)
     mch_memmove(newp + col, s, (size_t)newlen);
     mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
     ml_replace(lnum, newp, FALSE);
-    changed_bytes(lnum, col);
+    inserted_bytes(lnum, col, newlen);
     curwin->w_cursor.col += newlen;
 }
 
@@ -3016,6 +3015,21 @@ changed_bytes(linenr_T lnum, colnr_T col
 #endif
 }
 
+/*
+ * Like changed_bytes() but also adjust text properties for "added" bytes.
+ * When "added" is negative text was deleted.
+ */
+    void
+inserted_bytes(linenr_T lnum, colnr_T col, int added)
+{
+    changed_bytes(lnum, col);
+
+#ifdef FEAT_TEXT_PROP
+    if (curbuf->b_has_textprop && added != 0)
+	adjust_prop_columns(lnum, col, added);
+#endif
+}
+
     static void
 changedOneline(buf_T *buf, linenr_T lnum)
 {