From 437d35dbf7d9ff6f6e561377f5d23d7e4ac4d565 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 17 Jan 2024 13:31:07 +0100 Subject: fix(extmarks): do not remove invalid marks from decor upon deletion --- src/nvim/extmark.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 0321a11b0f..73a54729f8 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -150,7 +150,11 @@ void extmark_del(buf_T *buf, MarkTreeIter *itr, MTKey key, bool restore) } if (mt_decor_any(key)) { - buf_decor_remove(buf, key.pos.row, key2.pos.row, mt_decor(key), true); + if (mt_invalid(key)) { + decor_free(mt_decor(key)); + } else { + buf_decor_remove(buf, key.pos.row, key2.pos.row, mt_decor(key), true); + } } // TODO(bfredl): delete it from current undo header, opportunistically? @@ -393,10 +397,9 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo) } else if (undo_info.type == kExtmarkSavePos) { ExtmarkSavePos pos = undo_info.data.savepos; if (undo) { - if (pos.old_row >= 0) { - extmark_setraw(curbuf, pos.mark, pos.old_row, pos.old_col); - } - if (pos.invalidated) { + if (pos.old_row >= 0 + && extmark_setraw(curbuf, pos.mark, pos.old_row, pos.old_col) + && pos.invalidated) { MarkTreeIter itr[1] = { 0 }; MTKey mark = marktree_lookup(curbuf->b_marktree, pos.mark, itr); mt_itr_rawkey(itr).flags &= (uint16_t) ~MT_FLAG_INVALID; -- cgit From 2645c9d576e430e62b60d1902d4a6b887e46a670 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 17 Jan 2024 15:55:00 +0100 Subject: docs(extmarks): add undocumented "details" array fields --- src/nvim/api/extmark.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index fd07ec96fe..d7e1aa2d0f 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -215,8 +215,8 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, return extmark_to_array(extmark, false, details, hl_name); } -/// Gets |extmarks| (including |signs|) in "traversal order" from a |charwise| -/// region defined by buffer positions (inclusive, 0-indexed |api-indexing|). +/// Gets |extmarks| in "traversal order" from a |charwise| region defined by +/// buffer positions (inclusive, 0-indexed |api-indexing|). /// /// Region can be given as (row,col) tuples, or valid extmark ids (whose /// positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1) @@ -234,6 +234,10 @@ ArrayOf(Integer) nvim_buf_get_extmark_by_id(Buffer buffer, Integer ns_id, /// the `overlap` option might be useful. Otherwise only the start position /// of an extmark will be considered. /// +/// Note: legacy signs placed through the |:sign| commands are implemented +/// as extmarks and will show up here. Their details array will contain a +/// `sign_name` field. +/// /// Example: /// /// ```lua @@ -434,7 +438,9 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e /// if text around the mark was deleted and then restored by undo. /// Defaults to true. /// - invalidate : boolean that indicates whether to hide the -/// extmark if the entirety of its range is deleted. If +/// extmark if the entirety of its range is deleted. For +/// hidden marks, an "invalid" key is added to the "details" +/// array of |nvim_buf_get_extmarks()| and family. If /// "undo_restore" is false, the extmark is deleted instead. /// - priority: a priority value for the highlight group or sign /// attribute. For example treesitter highlighting uses a -- cgit From 18334a4a0cd9e5130237fc42dcd79d0a7d8e7d73 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 18 Jan 2024 19:54:45 +0100 Subject: refactor(extmarks): remove unused new pos from ExtmarkSavePos --- src/nvim/extmark.c | 20 +++++++------------- src/nvim/extmark.h | 2 -- 2 files changed, 7 insertions(+), 15 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index 73a54729f8..4e4db93a7b 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -356,14 +356,12 @@ void extmark_splice_delete(buf_T *buf, int l_row, colnr_T l_col, int u_row, coln // Push mark to undo header if (only_copy || (uvp != NULL && op == kExtmarkUndo && !mt_no_undo(mark))) { - ExtmarkSavePos pos; - pos.mark = mt_lookup_key(mark); - pos.invalidated = invalidated; - pos.old_row = mark.pos.row; - pos.old_col = mark.pos.col; - pos.row = -1; - pos.col = -1; - + ExtmarkSavePos pos = { + .mark = mt_lookup_key(mark), + .invalidated = invalidated, + .old_row = mark.pos.row, + .old_col = mark.pos.col + }; undo.data.savepos = pos; undo.type = kExtmarkSavePos; kv_push(*uvp, undo); @@ -406,12 +404,8 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo) MTPos end = marktree_get_altpos(curbuf->b_marktree, mark, itr); buf_put_decor(curbuf, mt_decor(mark), mark.pos.row, end.row); } - // Redo - } else { - if (pos.row >= 0) { - extmark_setraw(curbuf, pos.mark, pos.row, pos.col); - } } + // No Redo since kExtmarkSplice will move marks back } else if (undo_info.type == kExtmarkMove) { ExtmarkMove move = undo_info.data.move; if (undo) { diff --git a/src/nvim/extmark.h b/src/nvim/extmark.h index a68bbf33f2..b1ef5cf214 100644 --- a/src/nvim/extmark.h +++ b/src/nvim/extmark.h @@ -45,8 +45,6 @@ typedef struct { uint64_t mark; // raw mark id of the marktree int old_row; colnr_T old_col; - int row; - colnr_T col; bool invalidated; } ExtmarkSavePos; -- cgit