mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
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)
This commit is contained in:
44
src/undo.c
44
src/undo.c
@@ -375,6 +375,27 @@ u_save_line(undoline_T *ul, linenr_T lnum)
|
||||
return ul->ul_line == NULL ? FAIL : OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
@@ -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);
|
||||
|
Reference in New Issue
Block a user