mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 22:38:16 +00:00
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
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "nvim/charset.h"
|
||||
#include "nvim/cursor.h"
|
||||
#include "nvim/mark.h"
|
||||
#include "nvim/mark_extended.h"
|
||||
#include "nvim/memline.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/misc1.h"
|
||||
@@ -88,6 +89,7 @@ int get_indent_str(char_u *ptr, int ts, int list)
|
||||
// SIN_CHANGED: call changed_bytes() if the line was changed.
|
||||
// SIN_INSERT: insert the indent in front of the line.
|
||||
// SIN_UNDO: save line for undo before changing it.
|
||||
// SIN_NOMARK: don't move extmarks (because just after ml_append or something)
|
||||
// @param size measured in spaces
|
||||
// Returns true if the line was changed.
|
||||
int set_indent(int size, int flags)
|
||||
@@ -205,6 +207,7 @@ int set_indent(int size, int flags)
|
||||
// If 'preserveindent' and 'expandtab' are both set keep the original
|
||||
// characters and allocate accordingly. We will fill the rest with spaces
|
||||
// after the if (!curbuf->b_p_et) below.
|
||||
int skipcols = 0; // number of columns (in bytes) that were presved
|
||||
if (orig_char_len != -1) {
|
||||
int newline_size; // = orig_char_len + size - ind_done + line_len
|
||||
STRICT_ADD(orig_char_len, size, &newline_size, int);
|
||||
@@ -219,6 +222,7 @@ int set_indent(int size, int flags)
|
||||
ind_len = orig_char_len + todo;
|
||||
p = oldline;
|
||||
s = newline;
|
||||
skipcols = orig_char_len;
|
||||
|
||||
while (orig_char_len > 0) {
|
||||
*s++ = *p++;
|
||||
@@ -263,6 +267,7 @@ int set_indent(int size, int flags)
|
||||
ind_done++;
|
||||
}
|
||||
*s++ = *p++;
|
||||
skipcols++;
|
||||
}
|
||||
|
||||
// Fill to next tabstop with a tab, if possible.
|
||||
@@ -290,6 +295,13 @@ int set_indent(int size, int flags)
|
||||
// Replace the line (unless undo fails).
|
||||
if (!(flags & SIN_UNDO) || (u_savesub(curwin->w_cursor.lnum) == OK)) {
|
||||
ml_replace(curwin->w_cursor.lnum, newline, false);
|
||||
if (!(flags & SIN_NOMARK)) {
|
||||
extmark_splice(curbuf,
|
||||
(int)curwin->w_cursor.lnum-1, skipcols,
|
||||
0, (int)(p-oldline) - skipcols,
|
||||
0, (int)(s-newline) - skipcols,
|
||||
kExtmarkUndo);
|
||||
}
|
||||
|
||||
if (flags & SIN_CHANGED) {
|
||||
changed_bytes(curwin->w_cursor.lnum, 0);
|
||||
|
Reference in New Issue
Block a user