aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/extmark.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-11-03 12:26:38 +0100
committerbfredl <bjorn.linse@gmail.com>2023-11-05 12:18:29 +0100
commit68cb4a7405ea9f8841d1f25ee8997c49e77fa679 (patch)
treef2766eca6c0cb9fefb9739ffc3256649ba8d4a61 /src/nvim/api/extmark.c
parent92e99bb1058dd837c451675175efb8511c5f8e15 (diff)
downloadrneovim-68cb4a7405ea9f8841d1f25ee8997c49e77fa679.tar.gz
rneovim-68cb4a7405ea9f8841d1f25ee8997c49e77fa679.tar.bz2
rneovim-68cb4a7405ea9f8841d1f25ee8997c49e77fa679.zip
feat(extmarks): add "undo_restore" flag to opt out of undo-restoring
It is a design goal of extmarks that they allow precise tracking of changes across undo/redo, including restore the exact positions after a do/undo or undo/redo cycle. However this behavior is not useful for all usecases. Many plugins won't keep marks around for long after text changes, but uses them more like a cache until some external source (like LSP semantic highlights) has fully updated to changed text and then will explicitly readjust/replace extmarks as needed. Add a "undo_restore" flag which is true by default (matches existing behavior) but can be set to false to opt-out of this behavior. Delete dead u_extmark_set() code.
Diffstat (limited to 'src/nvim/api/extmark.c')
-rw-r--r--src/nvim/api/extmark.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 0b372c57e5..3f1745df40 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -166,6 +166,10 @@ static Array extmark_to_array(const ExtmarkInfo *extmark, bool id, bool add_dict
PUT(dict, "end_right_gravity", BOOLEAN_OBJ(extmark->end_right_gravity));
}
+ if (extmark->no_undo) {
+ PUT(dict, "undo_restore", BOOLEAN_OBJ(false));
+ }
+
const Decoration *decor = &extmark->decor;
if (decor->hl_id) {
PUT(dict, "hl_group", hl_group_name(decor->hl_id, hl_name));
@@ -519,6 +523,9 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// the extmark end position (if it exists) will be shifted
/// in when new text is inserted (true for right, false
/// for left). Defaults to false.
+/// - undo_restore : Restore the exact position of the mark
+/// if text around the mark was deleted and then restored by undo.
+/// Defaults to true.
/// - priority: a priority value for the highlight group or sign
/// attribute. For example treesitter highlighting uses a
/// value of 100.
@@ -825,7 +832,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
extmark_set(buf, (uint32_t)ns_id, &id, (int)line, (colnr_T)col, line2, col2,
has_decor ? &decor : NULL, right_gravity, end_right_gravity,
- kExtmarkNoUndo, err);
+ !GET_BOOL_OR_TRUE(opts, set_extmark, undo_restore), err);
if (ERROR_SET(err)) {
goto error;
}
@@ -952,7 +959,7 @@ Integer nvim_buf_add_highlight(Buffer buffer, Integer ns_id, String hl_group, In
extmark_set(buf, ns, NULL,
(int)line, (colnr_T)col_start,
end_line, (colnr_T)col_end,
- &decor, true, false, kExtmarkNoUndo, NULL);
+ &decor, true, false, false, NULL);
return ns_id;
}