diff src/edit.c @ 19097:bcbc9fe665b5 v8.2.0109

patch 8.2.0109: corrupted text properties when expanding spaces Commit: https://github.com/vim/vim/commit/ac15fd8c6761763c8feedef1a2fbd8309f0a823c Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 9 21:35:48 2020 +0100 patch 8.2.0109: corrupted text properties when expanding spaces Problem: Corrupted text properties when expanding spaces. Solution: Reallocate the line. (Nobuhiro Takasaki, closes https://github.com/vim/vim/issues/5457)
author Bram Moolenaar <Bram@vim.org>
date Thu, 09 Jan 2020 21:45:03 +0100
parents 143d44d8f477
children 06ef1e438ac8
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -5604,9 +5604,25 @@ ins_tab(void)
 #ifdef FEAT_PROP_POPUP
 		if (!(State & VREPLACE_FLAG))
 		{
-		    mch_memmove(ptr, ptr + i, curbuf->b_ml.ml_line_len - i
-					   - (ptr - curbuf->b_ml.ml_line_ptr));
+		    char_u  *newp;
+		    int	    col;
+
+		    newp = alloc(curbuf->b_ml.ml_line_len - i);
+		    if (newp == NULL)
+			return FALSE;
+
+		    col = ptr - curbuf->b_ml.ml_line_ptr;
+		    if (col > 0)
+			mch_memmove(newp, ptr - col, col);
+		    mch_memmove(newp + col, ptr + i,
+					   curbuf->b_ml.ml_line_len - col - i);
+
+		    if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY)
+			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_flags =
+			   (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
 		}
 		else
 #endif