patch 8.2.0844: text properties crossing lines not handled correctly

Problem:    Text properties crossing lines not handled correctly.
Solution:   When saving for undo include an extra line when needed and do not
            adjust properties when undoing. (Axel Forsman, closes #5875)
diff --git a/src/undo.c b/src/undo.c
index 4bbc0af..259de9a 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -376,6 +376,27 @@
 }
 
 /*
+ * return TRUE if line "lnum" has text property "flags".
+ */
+    static int
+has_prop_w_flags(linenr_T lnum, int flags)
+{
+    char_u  *props;
+    int	    i;
+    int	    proplen = get_text_props(curbuf, lnum, &props, FALSE);
+
+    for (i = 0; i < proplen; ++i)
+    {
+	textprop_T prop;
+
+	mch_memmove(&prop, props + i * sizeof prop, sizeof prop);
+	if (prop.tp_flags & flags)
+	    return TRUE;
+    }
+    return FALSE;
+}
+
+/*
  * Common code for various ways to save text before a change.
  * "top" is the line above the first changed line.
  * "bot" is the line below the last changed line.
@@ -450,6 +471,23 @@
     u_check(FALSE);
 #endif
 
+#ifdef FEAT_PROP_POPUP
+    // Include the line above if a text property continues from it.
+    // Include the line below if a text property continues to it.
+    if (bot - top > 1)
+    {
+	if (top > 0 && has_prop_w_flags(top + 1, TP_FLAG_CONT_PREV))
+	    --top;
+	if (bot <= curbuf->b_ml.ml_line_count
+			       && has_prop_w_flags(bot - 1, TP_FLAG_CONT_NEXT))
+	{
+	    ++bot;
+	    if (newbot != 0)
+		++newbot;
+	}
+    }
+#endif
+
     size = bot - top - 1;
 
     /*
@@ -2745,7 +2783,7 @@
 		// dummy empty line will be inserted
 		if (curbuf->b_ml.ml_line_count == 1)
 		    empty_buffer = TRUE;
-		ml_delete(lnum, FALSE);
+		ml_delete_flags(lnum, ML_DEL_UNDO);
 	    }
 	}
 	else
@@ -2767,8 +2805,8 @@
 		    ml_replace_len((linenr_T)1, uep->ue_array[i].ul_line,
 					  uep->ue_array[i].ul_len, TRUE, TRUE);
 		else
-		    ml_append(lnum, uep->ue_array[i].ul_line,
-				      (colnr_T)uep->ue_array[i].ul_len, FALSE);
+		    ml_append_flags(lnum, uep->ue_array[i].ul_line,
+			     (colnr_T)uep->ue_array[i].ul_len, ML_APPEND_UNDO);
 		vim_free(uep->ue_array[i].ul_line);
 	    }
 	    vim_free((char_u *)uep->ue_array);