fix(column): clear "b_signcols" before moving saved marks

Problem:  Marks moved by undo may be lost to "b_signcols.count".
Solution: Count signs for each undo object separately instead of
          once for the entire undo.
This commit is contained in:
Luuk van Baal
2024-01-27 13:04:58 +01:00
parent e35ae6fbc2
commit b50fdcba4a
5 changed files with 57 additions and 57 deletions

View File

@@ -2427,39 +2427,15 @@ static void u_undoredo(bool undo, bool do_buf_event)
curbuf->b_op_end.lnum = curbuf->b_ml.ml_line_count;
}
int row1 = MAXLNUM;
int row2 = -1;
int row3 = -1;
// Tricky: ExtmarkSavePos may come after ExtmarkSplice which does call
// buf_signcols_count_range() but then misses the yet unrestored marks.
if (curbuf->b_signcols.autom && buf_meta_total(curbuf, kMTMetaSignText)) {
for (int i = 0; i < (int)kv_size(curhead->uh_extmark); i++) {
ExtmarkUndoObject undo_info = kv_A(curhead->uh_extmark, i);
if (undo_info.type == kExtmarkSplice) {
ExtmarkSplice s = undo_info.data.splice;
if (s.old_row > 0 || s.new_row > 0) {
row1 = MIN(row1, s.start_row);
row2 = MAX(row2, s.start_row + (undo ? s.new_row : s.old_row) + 1);
row3 = MAX(row3, s.start_row + (undo ? s.old_row : s.new_row) + 1);
}
}
}
if (row2 != -1) {
// Remove signs inside edited region from "b_signcols.count".
buf_signcols_count_range(curbuf, row1, row2, 0, kTrue);
}
}
// Adjust Extmarks
if (undo) {
for (int i = (int)kv_size(curhead->uh_extmark) - 1; i > -1; i--) {
ExtmarkUndoObject undo_info = kv_A(curhead->uh_extmark, i);
extmark_apply_undo(undo_info, undo);
extmark_apply_undo(kv_A(curhead->uh_extmark, i), undo);
}
// redo
} else {
for (int i = 0; i < (int)kv_size(curhead->uh_extmark); i++) {
ExtmarkUndoObject undo_info = kv_A(curhead->uh_extmark, i);
extmark_apply_undo(undo_info, undo);
extmark_apply_undo(kv_A(curhead->uh_extmark, i), undo);
}
}
if (curhead->uh_flags & UH_RELOAD) {
@@ -2467,10 +2443,7 @@ static void u_undoredo(bool undo, bool do_buf_event)
// should have all info to send a buffer-reloaing on_lines/on_bytes event
buf_updates_unload(curbuf, true);
}
// Finish adjusting extmarks: add signs inside edited region to "b_signcols.count".
if (row2 != -1) {
buf_signcols_count_range(curbuf, row1, row3, 0, kNone);
}
// Finish adjusting extmarks
curhead->uh_entry = newlist;
curhead->uh_flags = new_flags;