diff src/textprop.c @ 16698:23af483c4ceb v8.1.1351

patch 8.1.1351: text property wrong after :substitute commit https://github.com/vim/vim/commit/338dfdad3844ebb1ce1d56c421d1f698c086eb0c Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 19 15:19:57 2019 +0200 patch 8.1.1351: text property wrong after :substitute Problem: Text property wrong after :substitute. Solution: Save for undo before changing any text properties.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 May 2019 15:30:07 +0200
parents 7847d281cbbf
children ba592f30c082
line wrap: on
line diff
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -957,13 +957,17 @@ clear_buf_prop_types(buf_T *buf)
  * shift by "bytes_added" (can be negative).
  * Note that "col" is zero-based, while tp_col is one-based.
  * Only for the current buffer.
+ * When "save_for_undo" is TRUE then call u_savesub() before making changes to
+ * the line.
  * Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
+ * Returns TRUE when props were changed.
  */
-    void
+    int
 adjust_prop_columns(
 	linenr_T    lnum,
 	colnr_T	    col,
-	int	    bytes_added)
+	int	    bytes_added,
+	int	    save_for_undo)
 {
     int		proplen;
     char_u	*props;
@@ -974,11 +978,11 @@ adjust_prop_columns(
     size_t	textlen;
 
     if (text_prop_frozen > 0)
-	return;
+	return FALSE;
 
     proplen = get_text_props(curbuf, lnum, &props, TRUE);
     if (proplen == 0)
-	return;
+	return FALSE;
     textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
 
     wi = 0; // write index
@@ -1001,6 +1005,9 @@ adjust_prop_columns(
 	    }
 	    else
 		tmp_prop.tp_col += bytes_added;
+	    // Save for undo if requested and not done yet.
+	    if (save_for_undo && !dirty)
+		u_savesub(lnum);
 	    dirty = TRUE;
 	    if (tmp_prop.tp_len <= 0)
 		continue;  // drop this text property
@@ -1016,6 +1023,9 @@ adjust_prop_columns(
 		tmp_prop.tp_len += bytes_added + after;
 	    else
 		tmp_prop.tp_len += bytes_added;
+	    // Save for undo if requested and not done yet.
+	    if (save_for_undo && !dirty)
+		u_savesub(lnum);
 	    dirty = TRUE;
 	    if (tmp_prop.tp_len <= 0)
 		continue;  // drop this text property
@@ -1034,6 +1044,7 @@ adjust_prop_columns(
 	curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
 	curbuf->b_ml.ml_line_len = newlen;
     }
+    return dirty;
 }
 
 /*