aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/extmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/extmark.c')
-rw-r--r--src/nvim/extmark.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c
index 3a04908ccb..17141f12fd 100644
--- a/src/nvim/extmark.c
+++ b/src/nvim/extmark.c
@@ -568,8 +568,18 @@ void extmark_splice(buf_T *buf,
int new_row, colnr_T new_col, bcount_t new_byte,
ExtmarkOp undo)
{
- long offset = ml_find_line_or_offset(buf, start_row+1, NULL, true);
- extmark_splice_impl(buf, start_row, start_col, offset+start_col,
+ long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true);
+
+ // On empty buffers, when editing the first line, the line is buffered,
+ // causing offset to be < 0. While the buffer is not actually empty, the
+ // buffered line has not been flushed (and should not be) yet, so the call is
+ // valid but an edge case.
+ //
+ // TODO(vigoux): maybe the is a better way of testing that ?
+ if (offset < 0 && buf->b_ml.ml_chunksize == NULL) {
+ offset = 0;
+ }
+ extmark_splice_impl(buf, start_row, start_col, offset + start_col,
old_row, old_col, old_byte, new_row, new_col, new_byte,
undo);
}
@@ -844,8 +854,15 @@ VirtText *extmark_find_virttext(buf_T *buf, int row, uint64_t ns_id)
bool decorations_redraw_reset(buf_T *buf, DecorationRedrawState *state)
{
state->row = -1;
+ for (size_t i = 0; i < kv_size(state->active); i++) {
+ HlRange item = kv_A(state->active, i);
+ if (item.virt_text_owned) {
+ clear_virttext(item.virt_text);
+ xfree(item.virt_text);
+ }
+ }
kv_size(state->active) = 0;
- return buf->b_extmark_index || buf->b_luahl;
+ return buf->b_extmark_index;
}
@@ -889,10 +906,10 @@ bool decorations_redraw_start(buf_T *buf, int top_row,
HlRange range;
if (mark.id&MARKTREE_END_FLAG) {
range = (HlRange){ altpos.row, altpos.col, mark.row, mark.col,
- attr_id, vt };
+ attr_id, vt, false };
} else {
range = (HlRange){ mark.row, mark.col, altpos.row,
- altpos.col, attr_id, vt };
+ altpos.col, attr_id, vt, false };
}
kv_push(state->active, range);
@@ -957,7 +974,7 @@ int decorations_redraw_col(buf_T *buf, int col, DecorationRedrawState *state)
VirtText *vt = kv_size(decor->virt_text) ? &decor->virt_text : NULL;
kv_push(state->active, ((HlRange){ mark.row, mark.col,
endpos.row, endpos.col,
- attr_id, vt }));
+ attr_id, vt, false }));
next_mark:
marktree_itr_next(buf->b_marktree, state->itr);
@@ -991,6 +1008,9 @@ next_mark:
}
if (keep) {
kv_A(state->active, j++) = kv_A(state->active, i);
+ } else if (item.virt_text_owned) {
+ clear_virttext(item.virt_text);
+ xfree(item.virt_text);
}
}
kv_size(state->active) = j;