@@ -3977,6 +3977,9 @@ ml_flush_line(buf_T *buf)
39773977 */
39783978 if ((int )dp -> db_free >= extra )
39793979 {
3980+ #ifdef FEAT_BYTEOFF
3981+ int old_prop_len = 0 ;
3982+ #endif
39803983 // if the length changes and there are following lines
39813984 count = buf -> b_ml .ml_locked_high - buf -> b_ml .ml_locked_low + 1 ;
39823985 if (extra != 0 && idx < count - 1 )
@@ -3995,13 +3998,24 @@ ml_flush_line(buf_T *buf)
39953998 // adjust free space
39963999 dp -> db_free -= extra ;
39974000 dp -> db_txt_start -= extra ;
4001+ #ifdef FEAT_BYTEOFF
4002+ if (buf -> b_has_textprop )
4003+ old_prop_len = old_len - STRLEN (new_line ) - 1 ;
4004+ #endif
39984005
39994006 // copy new line into the data block
40004007 mch_memmove (old_line - extra , new_line , (size_t )new_len );
40014008 buf -> b_ml .ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS );
40024009#ifdef FEAT_BYTEOFF
40034010 // The else case is already covered by the insert and delete
4004- ml_updatechunk (buf , lnum , (long )extra , ML_CHNK_UPDLINE );
4011+ if (buf -> b_has_textprop )
4012+ {
4013+ // Do not count the size of any text properties.
4014+ extra += old_prop_len ;
4015+ extra -= new_len - STRLEN (new_line ) - 1 ;
4016+ }
4017+ if (extra != 0 )
4018+ ml_updatechunk (buf , lnum , (long )extra , ML_CHNK_UPDLINE );
40054019#endif
40064020 }
40074021 else
@@ -5595,7 +5609,7 @@ ml_updatechunk(
55955609 else
55965610#endif
55975611 {
5598- if (idx == 0 )// first line in block, text at the end
5612+ if (idx == 0 ) // first line in block, text at the end
55995613 text_end = dp -> db_txt_end ;
56005614 else
56015615 text_end = ((dp -> db_index [idx - 1 ]) & DB_INDEX_MASK );
@@ -5734,7 +5748,7 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
57345748 return 1 ; // Not a "find offset" and offset 0 _must_ be in line 1
57355749 /*
57365750 * Find the last chunk before the one containing our line. Last chunk is
5737- * special because it will never qualify
5751+ * special because it will never qualify.
57385752 */
57395753 curline = 1 ;
57405754 curix = size = 0 ;
0 commit comments