fix(marks): revise metadata for start mark of revalidated pair #32017

Problem:  Metadata may be revised for end mark of a revalidated pair.
Solution: Revise metadata for start mark of a revalidated pair.
(cherry picked from commit 5cc93ef472)
This commit is contained in:
luukvbaal
2025-01-15 11:38:45 +01:00
committed by github-actions[bot]
parent 3b5c2213fd
commit e477ac7c45
2 changed files with 15 additions and 14 deletions

View File

@ -111,10 +111,10 @@ static void extmark_setraw(buf_T *buf, uint64_t mark, int row, colnr_T col, bool
{
MarkTreeIter itr[1] = { 0 };
MTKey key = marktree_lookup(buf->b_marktree, mark, itr);
bool move = key.pos.row >= 0 && (key.pos.row != row || key.pos.col != col);
// Already valid keys were being revalidated, presumably when encountering a
// SavePos from a modified mark. Avoid adding that to the decor again.
invalid = invalid && mt_invalid(key);
bool move = key.pos.row != row || key.pos.col != col;
if (key.pos.row < 0 || (!move && !invalid)) {
return; // Mark was deleted or no change needed
}
// Only the position before undo needs to be redrawn here,
// as the position after undo should be marked as changed.
@ -124,13 +124,16 @@ static void extmark_setraw(buf_T *buf, uint64_t mark, int row, colnr_T col, bool
int row1 = 0;
int row2 = 0;
MarkTreeIter altitr[1] = { *itr };
MTKey alt = marktree_get_alt(buf->b_marktree, key, altitr);
if (invalid) {
mt_itr_rawkey(itr).flags &= (uint16_t) ~MT_FLAG_INVALID;
marktree_revise_meta(buf->b_marktree, itr, key);
} else if (move && key.flags & MT_FLAG_DECOR_SIGNTEXT && buf->b_signcols.autom) {
MTPos end = marktree_get_altpos(buf->b_marktree, key, NULL);
row1 = MIN(end.row, MIN(key.pos.row, row));
row2 = MAX(end.row, MAX(key.pos.row, row));
mt_itr_rawkey(altitr).flags &= (uint16_t) ~MT_FLAG_INVALID;
marktree_revise_meta(buf->b_marktree, mt_end(key) ? altitr : itr, mt_end(key) ? alt : key);
} else if (!mt_invalid(key) && key.flags & MT_FLAG_DECOR_SIGNTEXT && buf->b_signcols.autom) {
row1 = MIN(alt.pos.row, MIN(key.pos.row, row));
row2 = MAX(alt.pos.row, MAX(key.pos.row, row));
buf_signcols_count_range(buf, row1, row2, 0, kTrue);
}
@ -139,10 +142,8 @@ static void extmark_setraw(buf_T *buf, uint64_t mark, int row, colnr_T col, bool
}
if (invalid) {
MTPos end = marktree_get_altpos(buf->b_marktree, key, itr);
mt_itr_rawkey(itr).flags &= (uint16_t) ~MT_FLAG_INVALID;
buf_put_decor(buf, mt_decor(key), row, end.row);
} else if (move && key.flags & MT_FLAG_DECOR_SIGNTEXT && buf->b_signcols.autom) {
buf_put_decor(buf, mt_decor(key), MIN(row, key.pos.row), MAX(row, key.pos.row));
} else if (!mt_invalid(key) && key.flags & MT_FLAG_DECOR_SIGNTEXT && buf->b_signcols.autom) {
buf_signcols_count_range(buf, row1, row2, 0, kNone);
}
}

View File

@ -1797,7 +1797,7 @@ describe('API/extmarks', function()
eq({}, get_extmark_by_id(ns, 4, {}))
end)
it('no crash checking invalided flag of sign pair end key #31856', function()
it('no crash checking invalidated flag of sign pair end key #31856', function()
api.nvim_buf_set_lines(0, 0, 1, false, { '', '' })
api.nvim_set_option_value('signcolumn', 'auto:2', {})
set_extmark(ns, 1, 0, 0, { sign_text = 'S1', invalidate = true, end_row = 0 })