diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-06-02 15:00:16 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-06-02 15:03:53 +0800 |
commit | 97d9d71bf3ccc156b94acf988f6b2f60fb706fc9 (patch) | |
tree | f1392af05e9dad14dc2371b6be851967164357c3 /src/nvim/edit.c | |
parent | 4374ec83cd49d148fc788bdb43f49d4b0365cf9f (diff) | |
download | rneovim-97d9d71bf3ccc156b94acf988f6b2f60fb706fc9.tar.gz rneovim-97d9d71bf3ccc156b94acf988f6b2f60fb706fc9.tar.bz2 rneovim-97d9d71bf3ccc156b94acf988f6b2f60fb706fc9.zip |
vim-patch:8.2.0109: corrupted text properties when expanding spaces
Problem: Corrupted text properties when expanding spaces.
Solution: Reallocate the line. (Nobuhiro Takasaki, closes vim/vim#5457)
https://github.com/vim/vim/commit/ac15fd8c6761763c8feedef1a2fbd8309f0a823c
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r-- | src/nvim/edit.c | 13 |
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 { |