fix(extmark): restore extmarks when completing original text

This commit is contained in:
Luuk van Baal
2023-05-22 16:57:30 +02:00
parent 400b7842a9
commit 8e97edb93f
3 changed files with 83 additions and 9 deletions

View File

@@ -311,9 +311,8 @@ void extmark_free_all(buf_T *buf)
/// copying is useful when we cannot simply reverse the operation. This will do
/// nothing on redo, enforces correct position when undo.
void extmark_splice_delete(buf_T *buf, int l_row, colnr_T l_col, int u_row, colnr_T u_col,
ExtmarkOp op)
extmark_undo_vec_t *uvp, bool only_copy, ExtmarkOp op)
{
u_header_T *uhp = u_force_get_undo_header(buf);
MarkTreeIter itr[1] = { 0 };
ExtmarkUndoObject undo;
@@ -328,7 +327,7 @@ void extmark_splice_delete(buf_T *buf, int l_row, colnr_T l_col, int u_row, coln
bool invalidated = false;
// Invalidate/delete mark
if (!mt_invalid(mark) && mt_invalidate(mark) && !mt_end(mark)) {
if (!only_copy && !mt_invalid(mark) && mt_invalidate(mark) && !mt_end(mark)) {
MTPos endpos = marktree_get_altpos(buf->b_marktree, mark, NULL);
if (endpos.row < 0) {
endpos = mark.pos;
@@ -348,7 +347,7 @@ void extmark_splice_delete(buf_T *buf, int l_row, colnr_T l_col, int u_row, coln
}
// Push mark to undo header
if (uhp && op == kExtmarkUndo && !mt_no_undo(mark)) {
if (only_copy || (uvp != NULL && op == kExtmarkUndo && !mt_no_undo(mark))) {
ExtmarkSavePos pos;
pos.mark = mt_lookup_key(mark);
pos.invalidated = invalidated;
@@ -359,7 +358,7 @@ void extmark_splice_delete(buf_T *buf, int l_row, colnr_T l_col, int u_row, coln
undo.data.savepos = pos;
undo.type = kExtmarkSavePos;
kv_push(uhp->uh_extmark, undo);
kv_push(*uvp, undo);
}
marktree_itr_next(buf->b_marktree, itr);
@@ -511,7 +510,9 @@ void extmark_splice_impl(buf_T *buf, int start_row, colnr_T start_col, bcount_t
// merge!)
int end_row = start_row + old_row;
int end_col = (old_row ? 0 : start_col) + old_col;
extmark_splice_delete(buf, start_row, start_col, end_row, end_col, undo);
u_header_T *uhp = u_force_get_undo_header(buf);
extmark_undo_vec_t *uvp = uhp ? &uhp->uh_extmark : NULL;
extmark_splice_delete(buf, start_row, start_col, end_row, end_col, uvp, false, undo);
}
// Move the signcolumn sentinel line