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)

b413d2e6a8

Co-authored-by: Bram Moolenaar <Bram@vim.org>
(cherry picked from commit 36fc266e86)
This commit is contained in:
Jan Edmund Lazo
2025-08-09 22:15:50 -04:00
committed by github-actions[bot]
parent 4cc060bf44
commit c2a3838ab2

View File

@@ -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;