neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 97d9d71bf3ccc156b94acf988f6b2f60fb706fc9
parent 4374ec83cd49d148fc788bdb43f49d4b0365cf9f
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sun,  2 Jun 2024 15:00:16 +0800

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:
Msrc/nvim/edit.c | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git 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 {