neovim

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

commit 36fc266e86897ad4dd60dabdbfde786f8861e138
parent 03c953008c2b24f2b1476466b45f2a9d791fc6cb
Author: Jan Edmund Lazo <jan.lazo@mail.utoronto.ca>
Date:   Sat,  9 Aug 2025 22:15:50 -0400

vim-patch:8.1.0636: line2byte() gives wrong values with text properties

Problem:    line2byte() gives wrong values with text properties. (Bjorn Linse)
Solution:   Compute byte offsets differently when text properties were added.
            (closes vim/vim#3718)

https://github.com/vim/vim/commit/b413d2e6a8cc7b1611a41bfa9462b986393ca5fe

Co-authored-by: Bram Moolenaar <Bram@vim.org>

Diffstat:
Msrc/nvim/memline.c | 19++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/nvim/memline.c b/src/nvim/memline.c @@ -3794,6 +3794,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, int len, int updtype) } if (buf->b_ml.ml_chunksize[curix].mlcs_numlines >= MLCS_MAXL) { + int end_idx; int text_end; memmove(buf->b_ml.ml_chunksize + curix + 1, @@ -3813,21 +3814,21 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, int len, int updtype) = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; // number of entries in block int idx = curline - buf->b_ml.ml_locked_low; curline = buf->b_ml.ml_locked_high + 1; - if (idx == 0) { // first line in block, text at the end - text_end = (int)dp->db_txt_end; - } else { - text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); - } - // Compute index of last line to use in this MEMLINE + // compute index of last line to use in this MEMLINE rest = count - idx; if (linecnt + rest > MLCS_MINL) { - idx += MLCS_MINL - linecnt - 1; + end_idx = idx + MLCS_MINL - linecnt - 1; linecnt = MLCS_MINL; } else { - idx = count - 1; + end_idx = count - 1; linecnt += rest; } - size += text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK); + if (idx == 0) { // first line in block, text at the end + text_end = (int)dp->db_txt_end; + } else { + text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); + } + size += text_end - (int)((dp->db_index[end_idx]) & DB_INDEX_MASK); } buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt; buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt;