comparison src/memline.c @ 29682:57cfb39b7842 v9.0.0181

patch 9.0.0181: textprop test with line2byte() fails on MS-Windows Commit: https://github.com/vim/vim/commit/e5a0e8c1d781aa3781b4f6167fc2cba1193213f1 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 9 21:37:55 2022 +0100 patch 9.0.0181: textprop test with line2byte() fails on MS-Windows Problem: Textprop test with line2byte() fails on MS-Windows. Solution: Fix updating chuncks in ml_delete_int().
author Bram Moolenaar <Bram@vim.org>
date Tue, 09 Aug 2022 22:45:03 +0200
parents 23dceecc0bf8
children 89e1d67814a9
comparison
equal deleted inserted replaced
29681:b766ffb853c0 29682:57cfb39b7842
3311 ml_updatechunk(buf, lnum + 1, 3311 ml_updatechunk(buf, lnum + 1,
3312 # ifdef FEAT_PROP_POPUP 3312 # ifdef FEAT_PROP_POPUP
3313 (long)text_len 3313 (long)text_len
3314 # else 3314 # else
3315 (long)len 3315 (long)len
3316 #endif 3316 # endif
3317 , ML_CHNK_ADDLINE); 3317 , ML_CHNK_ADDLINE);
3318 #endif 3318 #endif
3319 3319
3320 #ifdef FEAT_NETBEANS_INTG 3320 #ifdef FEAT_NETBEANS_INTG
3321 if (netbeans_active()) 3321 if (netbeans_active())
3665 long line_size; 3665 long line_size;
3666 int i; 3666 int i;
3667 int ret = FAIL; 3667 int ret = FAIL;
3668 #ifdef FEAT_PROP_POPUP 3668 #ifdef FEAT_PROP_POPUP
3669 char_u *textprop_save = NULL; 3669 char_u *textprop_save = NULL;
3670 int textprop_save_len = 0; 3670 long textprop_len = 0;
3671 #endif 3671 #endif
3672 3672
3673 if (lowest_marked && lowest_marked > lnum) 3673 if (lowest_marked && lowest_marked > lnum)
3674 lowest_marked--; 3674 lowest_marked--;
3675 3675
3721 #ifdef FEAT_NETBEANS_INTG 3721 #ifdef FEAT_NETBEANS_INTG
3722 if (netbeans_active()) 3722 if (netbeans_active())
3723 netbeans_removed(buf, lnum, 0, line_size); 3723 netbeans_removed(buf, lnum, 0, line_size);
3724 #endif 3724 #endif
3725 #ifdef FEAT_PROP_POPUP 3725 #ifdef FEAT_PROP_POPUP
3726 // If there are text properties, make a copy, so that we can update 3726 // If there are text properties compute their byte length.
3727 // properties in preceding and following lines. 3727 // if needed make a copy, so that we can update properties in preceding and
3728 if (buf->b_has_textprop && !(flags & (ML_DEL_UNDO | ML_DEL_NOPROP))) 3728 // following lines.
3729 if (buf->b_has_textprop)
3729 { 3730 {
3730 size_t textlen = STRLEN((char_u *)dp + line_start) + 1; 3731 size_t textlen = STRLEN((char_u *)dp + line_start) + 1;
3731 3732
3732 if ((long)textlen < line_size) 3733 textprop_len = line_size - (long)textlen;
3733 { 3734 if (!(flags & (ML_DEL_UNDO | ML_DEL_NOPROP)) && textprop_len > 0)
3734 textprop_save_len = line_size - (int)textlen;
3735 textprop_save = vim_memsave((char_u *)dp + line_start + textlen, 3735 textprop_save = vim_memsave((char_u *)dp + line_start + textlen,
3736 textprop_save_len); 3736 textprop_len);
3737 }
3738 } 3737 }
3739 #endif 3738 #endif
3740 3739
3741 /* 3740 /*
3742 * special case: If there is only one line in the data block it becomes empty. 3741 * special case: If there is only one line in the data block it becomes empty.
3818 } 3817 }
3819 3818
3820 #ifdef FEAT_BYTEOFF 3819 #ifdef FEAT_BYTEOFF
3821 ml_updatechunk(buf, lnum, line_size 3820 ml_updatechunk(buf, lnum, line_size
3822 # ifdef FEAT_PROP_POPUP 3821 # ifdef FEAT_PROP_POPUP
3823 - textprop_save_len 3822 - textprop_len
3824 # endif 3823 # endif
3825 , ML_CHNK_DELLINE); 3824 , ML_CHNK_DELLINE);
3826 #endif 3825 #endif
3827 ret = OK; 3826 ret = OK;
3828 3827
3829 theend: 3828 theend:
3830 #ifdef FEAT_PROP_POPUP 3829 #ifdef FEAT_PROP_POPUP
3831 if (textprop_save != NULL) 3830 if (textprop_save != NULL)
3832 { 3831 {
3833 // Adjust text properties in the line above and below. 3832 // Adjust text properties in the line above and below.
3834 if (lnum > 1) 3833 if (lnum > 1)
3835 adjust_text_props_for_delete(buf, lnum - 1, textprop_save, 3834 adjust_text_props_for_delete(buf, lnum - 1, textprop_save,
3836 textprop_save_len, TRUE); 3835 (int)textprop_len, TRUE);
3837 if (lnum <= buf->b_ml.ml_line_count) 3836 if (lnum <= buf->b_ml.ml_line_count)
3838 adjust_text_props_for_delete(buf, lnum, textprop_save, 3837 adjust_text_props_for_delete(buf, lnum, textprop_save,
3839 textprop_save_len, FALSE); 3838 (int)textprop_len, FALSE);
3840 } 3839 }
3841 vim_free(textprop_save); 3840 vim_free(textprop_save);
3842 #endif 3841 #endif
3843 return ret; 3842 return ret;
3844 } 3843 }
5682 5681
5683 // We cannot use the text pointers to get the text length, 5682 // We cannot use the text pointers to get the text length,
5684 // the text prop info would also be counted. Go over the 5683 // the text prop info would also be counted. Go over the
5685 // lines. 5684 // lines.
5686 for (i = end_idx; i < idx; ++i) 5685 for (i = end_idx; i < idx; ++i)
5687 size += (int)STRLEN((char_u *)dp + (dp->db_index[i] & DB_INDEX_MASK)) + 1; 5686 size += (int)STRLEN((char_u *)dp
5687 + (dp->db_index[i] & DB_INDEX_MASK)) + 1;
5688 } 5688 }
5689 else 5689 else
5690 #endif 5690 #endif
5691 { 5691 {
5692 if (idx == 0) // first line in block, text at the end 5692 if (idx == 0) // first line in block, text at the end
5693 text_end = dp->db_txt_end; 5693 text_end = dp->db_txt_end;
5694 else 5694 else
5695 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); 5695 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
5696 size += text_end - ((dp->db_index[end_idx]) & DB_INDEX_MASK); 5696 size += text_end
5697 - ((dp->db_index[end_idx]) & DB_INDEX_MASK);
5697 } 5698 }
5698 } 5699 }
5699 buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt; 5700 buf->b_ml.ml_chunksize[curix].mlcs_numlines = linecnt;
5700 buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt; 5701 buf->b_ml.ml_chunksize[curix + 1].mlcs_numlines -= linecnt;
5701 buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size; 5702 buf->b_ml.ml_chunksize[curix].mlcs_totalsize = size;
5747 } 5748 }
5748 else if (updtype == ML_CHNK_DELLINE) 5749 else if (updtype == ML_CHNK_DELLINE)
5749 { 5750 {
5750 curchnk->mlcs_numlines--; 5751 curchnk->mlcs_numlines--;
5751 ml_upd_lastbuf = NULL; // Force recalc of curix & curline 5752 ml_upd_lastbuf = NULL; // Force recalc of curix & curline
5752 if (curix < (buf->b_ml.ml_usedchunks - 1) 5753 if (curix < buf->b_ml.ml_usedchunks - 1
5753 && (curchnk->mlcs_numlines + curchnk[1].mlcs_numlines) 5754 && curchnk->mlcs_numlines + curchnk[1].mlcs_numlines
5754 <= MLCS_MINL) 5755 <= MLCS_MINL)
5755 { 5756 {
5756 curix++; 5757 curix++;
5757 curchnk = buf->b_ml.ml_chunksize + curix; 5758 curchnk = buf->b_ml.ml_chunksize + curix;
5758 } 5759 }
5759 else if (curix == 0 && curchnk->mlcs_numlines <= 0) 5760 else if (curix == 0 && curchnk->mlcs_numlines <= 0)
5762 mch_memmove(buf->b_ml.ml_chunksize, buf->b_ml.ml_chunksize + 1, 5763 mch_memmove(buf->b_ml.ml_chunksize, buf->b_ml.ml_chunksize + 1,
5763 buf->b_ml.ml_usedchunks * sizeof(chunksize_T)); 5764 buf->b_ml.ml_usedchunks * sizeof(chunksize_T));
5764 return; 5765 return;
5765 } 5766 }
5766 else if (curix == 0 || (curchnk->mlcs_numlines > 10 5767 else if (curix == 0 || (curchnk->mlcs_numlines > 10
5767 && (curchnk->mlcs_numlines + curchnk[-1].mlcs_numlines) 5768 && curchnk->mlcs_numlines + curchnk[-1].mlcs_numlines
5768 > MLCS_MINL)) 5769 > MLCS_MINL))
5769 { 5770 {
5770 return; 5771 return;
5771 } 5772 }
5772 5773
5773 // Collapse chunks 5774 // Collapse chunks
5774 curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines; 5775 curchnk[-1].mlcs_numlines += curchnk->mlcs_numlines;
5775 curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize; 5776 curchnk[-1].mlcs_totalsize += curchnk->mlcs_totalsize;
5776 buf->b_ml.ml_usedchunks--; 5777 buf->b_ml.ml_usedchunks--;
5777 if (curix < buf->b_ml.ml_usedchunks) 5778 if (curix < buf->b_ml.ml_usedchunks)
5778 {
5779 mch_memmove(buf->b_ml.ml_chunksize + curix, 5779 mch_memmove(buf->b_ml.ml_chunksize + curix,
5780 buf->b_ml.ml_chunksize + curix + 1, 5780 buf->b_ml.ml_chunksize + curix + 1,
5781 (buf->b_ml.ml_usedchunks - curix) * 5781 (buf->b_ml.ml_usedchunks - curix) *
5782 sizeof(chunksize_T)); 5782 sizeof(chunksize_T));
5783 }
5784 return; 5783 return;
5785 } 5784 }
5786 ml_upd_lastbuf = buf; 5785 ml_upd_lastbuf = buf;
5787 ml_upd_lastline = line; 5786 ml_upd_lastline = line;
5788 ml_upd_lastcurline = curline; 5787 ml_upd_lastcurline = curline;