From c2a3838ab248d43213fdf5dfd5c1cdbe83d06f14 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 9 Aug 2025 22:15:50 -0400 Subject: [PATCH] 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 (cherry picked from commit 36fc266e86897ad4dd60dabdbfde786f8861e138) --- src/nvim/memline.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 1054e40190..33ab0f9382 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -3792,6 +3792,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, @@ -3811,21 +3812,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 + // compute index of last line to use in this MEMLINE + rest = count - idx; + if (linecnt + rest > MLCS_MINL) { + end_idx = idx + MLCS_MINL - linecnt - 1; + linecnt = MLCS_MINL; + } else { + end_idx = count - 1; + linecnt += rest; + } + 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 - rest = count - idx; - if (linecnt + rest > MLCS_MINL) { - idx += MLCS_MINL - linecnt - 1; - linecnt = MLCS_MINL; - } else { - idx = count - 1; - linecnt += rest; - } - size += text_end - (int)((dp->db_index[idx]) & 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;