summaryrefslogtreecommitdiff
path: root/src/undo.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-05-30 14:46:52 +0200
committerBram Moolenaar <Bram@vim.org>2020-05-30 14:46:52 +0200
commita9d4b84d97fb74061eeb42c1433e111fb58825dc (patch)
tree0d8a57baabbdc18ac8c265f2e9fa8c39dac43e70 /src/undo.c
parent0016fd2e29b7d4d4eef89a0516d14888a8651c61 (diff)
downloadvim-git-a9d4b84d97fb74061eeb42c1433e111fb58825dc.tar.gz
patch 8.2.0844: text properties crossing lines not handled correctlyv8.2.0844
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)
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/undo.c b/src/undo.c
index 4bbc0af0f..259de9ab2 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -376,6 +376,27 @@ u_save_line(undoline_T *ul, linenr_T lnum)
}
/*
+ * 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_savecommon(
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 @@ u_undoredo(int undo)
// 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 @@ u_undoredo(int undo)
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);