@@ -3179,14 +3179,14 @@ ml_replace_len(linenr_T lnum, char_u *line_arg, colnr_T len_arg, int copy)
31793179 curbuf -> b_ml .ml_flags &= ~ML_LINE_DIRTY ;
31803180
31813181#ifdef FEAT_TEXT_PROP
3182- if (has_any_text_properties ( curbuf ) )
3182+ if (curbuf -> b_has_textprop )
31833183 // Need to fetch the old line to copy over any text properties.
31843184 ml_get_buf (curbuf , lnum , TRUE);
31853185#endif
31863186 }
31873187
31883188#ifdef FEAT_TEXT_PROP
3189- if (has_any_text_properties ( curbuf ) )
3189+ if (curbuf -> b_has_textprop )
31903190 {
31913191 size_t oldtextlen = STRLEN (curbuf -> b_ml .ml_line_ptr ) + 1 ;
31923192
@@ -5131,6 +5131,7 @@ ml_updatechunk(
51315131 {
51325132 int count ; /* number of entries in block */
51335133 int idx ;
5134+ int end_idx ;
51345135 int text_end ;
51355136 int linecnt ;
51365137
@@ -5154,23 +5155,39 @@ ml_updatechunk(
51545155 (long )(buf -> b_ml .ml_locked_low ) + 1 ;
51555156 idx = curline - buf -> b_ml .ml_locked_low ;
51565157 curline = buf -> b_ml .ml_locked_high + 1 ;
5157- if (idx == 0 )/* first line in block, text at the end */
5158- text_end = dp -> db_txt_end ;
5159- else
5160- text_end = ((dp -> db_index [idx - 1 ]) & DB_INDEX_MASK );
5161- /* Compute index of last line to use in this MEMLINE */
5158+
5159+ // compute index of last line to use in this MEMLINE
51625160 rest = count - idx ;
51635161 if (linecnt + rest > MLCS_MINL )
51645162 {
5165- idx += MLCS_MINL - linecnt - 1 ;
5163+ end_idx = idx + MLCS_MINL - linecnt - 1 ;
51665164 linecnt = MLCS_MINL ;
51675165 }
51685166 else
51695167 {
5170- idx = count - 1 ;
5168+ end_idx = count - 1 ;
51715169 linecnt += rest ;
51725170 }
5173- size += text_end - ((dp -> db_index [idx ]) & DB_INDEX_MASK );
5171+ #ifdef FEAT_TEXT_PROP
5172+ if (buf -> b_has_textprop )
5173+ {
5174+ int i ;
5175+
5176+ // We cannot use the text pointers to get the text length,
5177+ // the text prop info would also be counted. Go over the
5178+ // lines.
5179+ for (i = end_idx ; i < idx ; ++ i )
5180+ size += STRLEN ((char_u * )dp + (dp -> db_index [i ] & DB_INDEX_MASK )) + 1 ;
5181+ }
5182+ else
5183+ #endif
5184+ {
5185+ if (idx == 0 )/* first line in block, text at the end */
5186+ text_end = dp -> db_txt_end ;
5187+ else
5188+ text_end = ((dp -> db_index [idx - 1 ]) & DB_INDEX_MASK );
5189+ size += text_end - ((dp -> db_index [end_idx ]) & DB_INDEX_MASK );
5190+ }
51745191 }
51755192 buf -> b_ml .ml_chunksize [curix ].mlcs_numlines = linecnt ;
51765193 buf -> b_ml .ml_chunksize [curix + 1 ].mlcs_numlines -= linecnt ;
@@ -5360,7 +5377,20 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
53605377 idx ++ ;
53615378 }
53625379 }
5363- len = text_end - ((dp -> db_index [idx ]) & DB_INDEX_MASK );
5380+ #ifdef FEAT_TEXT_PROP
5381+ if (buf -> b_has_textprop )
5382+ {
5383+ int i ;
5384+
5385+ // cannot use the db_index pointer, need to get the actual text
5386+ // lengths.
5387+ len = 0 ;
5388+ for (i = start_idx ; i <= idx ; ++ i )
5389+ len += STRLEN ((char_u * )dp + ((dp -> db_index [idx ]) & DB_INDEX_MASK )) + 1 ;
5390+ }
5391+ else
5392+ #endif
5393+ len = text_end - ((dp -> db_index [idx ]) & DB_INDEX_MASK );
53645394 size += len ;
53655395 if (offset != 0 && size >= offset )
53665396 {
0 commit comments