From ca1a00edd6d6345b848a28d077d6a192528f811e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 14 Jan 2020 12:45:09 +0100 Subject: extmarks/bufhl: reimplement using new marktree data structure Add new "splice" interface for tracking buffer changes at the byte level. This will later be reused for byte-resolution buffer updates. (Implementation has been started, but using undocumented "_on_bytes" option now as interface hasn't been finalized). Use this interface to improve many edge cases of extmark adjustment. Changed tests indicate previously incorrect behavior. Adding tests for more edge cases will be follow-up work (overlaps on_bytes tests) Don't consider creation/deletion of marks an undoable event by itself. This behavior was never documented, and imposes complexity for little gain. Add nvim__buf_add_decoration temporary API for direct access to the new implementation. This should be refactored into a proper API for decorations, probably involving a huge dict. fixes #11598 --- src/nvim/mark_extended_defs.h | 59 +++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) (limited to 'src/nvim/mark_extended_defs.h') diff --git a/src/nvim/mark_extended_defs.h b/src/nvim/mark_extended_defs.h index 565c599d06..439f7f0b36 100644 --- a/src/nvim/mark_extended_defs.h +++ b/src/nvim/mark_extended_defs.h @@ -2,53 +2,36 @@ #define NVIM_MARK_EXTENDED_DEFS_H #include "nvim/pos.h" // for colnr_T -#include "nvim/map.h" // for uint64_t -#include "nvim/lib/kbtree.h" #include "nvim/lib/kvec.h" -struct ExtmarkLine; +typedef struct { + char *text; + int hl_id; +} VirtTextChunk; -typedef struct Extmark +typedef kvec_t(VirtTextChunk) VirtText; +#define VIRTTEXT_EMPTY ((VirtText)KV_INITIAL_VALUE) + +typedef struct { uint64_t ns_id; uint64_t mark_id; - struct ExtmarkLine *line; - colnr_T col; -} Extmark; - - -// We only need to compare columns as rows are stored in a different tree. -// Marks are ordered by: position, namespace, mark_id -// This improves moving marks but slows down all other use cases (searches) -static inline int extmark_cmp(Extmark a, Extmark b) -{ - int cmp = kb_generic_cmp(a.col, b.col); - if (cmp != 0) { - return cmp; - } - cmp = kb_generic_cmp(a.ns_id, b.ns_id); - if (cmp != 0) { - return cmp; - } - return kb_generic_cmp(a.mark_id, b.mark_id); -} - - -#define markitems_cmp(a, b) (extmark_cmp((a), (b))) -KBTREE_INIT(markitems, Extmark, markitems_cmp, 10) - -typedef struct ExtmarkLine -{ - linenr_T lnum; - kbtree_t(markitems) items; -} ExtmarkLine; - -#define EXTMARKLINE_CMP(a, b) (kb_generic_cmp((a)->lnum, (b)->lnum)) -KBTREE_INIT(extmarklines, ExtmarkLine *, EXTMARKLINE_CMP, 10) - + int hl_id; // highlight group + // TODO(bfredl): virt_text is pretty larger than the rest, + // pointer indirection? + VirtText virt_text; +} ExtmarkItem; typedef struct undo_object ExtmarkUndoObject; typedef kvec_t(ExtmarkUndoObject) extmark_undo_vec_t; +// Undo/redo extmarks + +typedef enum { + kExtmarkNOOP, // Extmarks shouldn't be moved + kExtmarkUndo, // Operation should be reversable/undoable + kExtmarkNoUndo, // Operation should not be reversable + kExtmarkUndoNoRedo, // Operation should be undoable, but not redoable +} ExtmarkOp; #endif // NVIM_MARK_EXTENDED_DEFS_H -- cgit