aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/edit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r--src/nvim/edit.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 436d43a4db..f6e2dbfa4e 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -4422,9 +4422,18 @@ static bool ins_tab(void)
int i = cursor->col - fpos.col;
if (i > 0) {
if (!(State & VREPLACE_FLAG)) {
- memmove(ptr, ptr + i, (size_t)(curbuf->b_ml.ml_line_len - i
- - (ptr - curbuf->b_ml.ml_line_ptr)));
+ char *newp = xmalloc((size_t)(curbuf->b_ml.ml_line_len - i));
+ ptrdiff_t col = ptr - curbuf->b_ml.ml_line_ptr;
+ if (col > 0) {
+ memmove(newp, ptr - col, (size_t)col);
+ }
+ memmove(newp + col, ptr + i, (size_t)(curbuf->b_ml.ml_line_len - col - i));
+ if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) {
+ xfree(curbuf->b_ml.ml_line_ptr);
+ }
+ curbuf->b_ml.ml_line_ptr = newp;
curbuf->b_ml.ml_line_len -= i;
+ curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
inserted_bytes(fpos.lnum, change_col,
cursor->col - change_col, fpos.col - change_col);
} else {