comparison src/memline.c @ 23776:9f692a75d481 v8.2.2429

patch 8.2.2429: :goto does not work correctly with text properties Commit: https://github.com/vim/vim/commit/59ff64079b4fcf0393a7413e3242a8b58c2ceadb Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 30 17:16:28 2021 +0100 patch 8.2.2429: :goto does not work correctly with text properties Problem: :goto does not work correctly with text properties. (Sam McCall) Solution: Add a test. (Andrew Radev) Also use the text property size when computing the remaining offset. (closes #5930)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 Jan 2021 17:30:03 +0100
parents b545334ae654
children cdeec1389c8c
comparison
equal deleted inserted replaced
23775:86461330648b 23776:9f692a75d481
5699 curix++; 5699 curix++;
5700 } 5700 }
5701 5701
5702 while ((lnum != 0 && curline < lnum) || (offset != 0 && size < offset)) 5702 while ((lnum != 0 && curline < lnum) || (offset != 0 && size < offset))
5703 { 5703 {
5704 #ifdef FEAT_PROP_POPUP
5705 size_t textprop_total = 0;
5706 #endif
5707
5704 if (curline > buf->b_ml.ml_line_count 5708 if (curline > buf->b_ml.ml_line_count
5705 || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL) 5709 || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL)
5706 return -1; 5710 return -1;
5707 dp = (DATA_BL *)(hp->bh_data); 5711 dp = (DATA_BL *)(hp->bh_data);
5708 count = (long)(buf->b_ml.ml_locked_high) - 5712 count = (long)(buf->b_ml.ml_locked_high) -
5720 else 5724 else
5721 idx = count - 1; 5725 idx = count - 1;
5722 } 5726 }
5723 else 5727 else
5724 { 5728 {
5725 #ifdef FEAT_PROP_POPUP
5726 size_t textprop_total = 0;
5727 size_t textprop_size = 0;
5728 char_u *l1, *l2;
5729 #endif
5730
5731 extra = 0; 5729 extra = 0;
5732 for (;;) 5730 for (;;)
5733 { 5731 {
5734 #ifdef FEAT_PROP_POPUP 5732 #ifdef FEAT_PROP_POPUP
5733 size_t textprop_size = 0;
5734
5735 if (buf->b_has_textprop) 5735 if (buf->b_has_textprop)
5736 { 5736 {
5737 char_u *l1, *l2;
5738
5737 // compensate for the extra bytes taken by textprops 5739 // compensate for the extra bytes taken by textprops
5738 l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK); 5740 l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK);
5739 l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end 5741 l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end
5740 : ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); 5742 : ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
5741 textprop_size = (l2 - l1) - (STRLEN(l1) + 1); 5743 textprop_size = (l2 - l1) - (STRLEN(l1) + 1);
5761 } 5763 }
5762 idx++; 5764 idx++;
5763 } 5765 }
5764 } 5766 }
5765 #ifdef FEAT_PROP_POPUP 5767 #ifdef FEAT_PROP_POPUP
5766 if (buf->b_has_textprop) 5768 if (buf->b_has_textprop && lnum != 0)
5767 { 5769 {
5768 int i; 5770 int i;
5769 5771
5770 // cannot use the db_index pointer, need to get the actual text 5772 // cannot use the db_index pointer, need to get the actual text
5771 // lengths. 5773 // lengths.
5772 len = 0; 5774 len = 0;
5773 for (i = start_idx; i <= idx; ++i) 5775 for (i = start_idx; i <= idx; ++i)
5774 len += (int)STRLEN((char_u *)dp 5776 {
5775 + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1; 5777 char_u *p = (char_u *)dp + ((dp->db_index[i]) & DB_INDEX_MASK);
5778 len += (int)STRLEN(p) + 1;
5779 }
5776 } 5780 }
5777 else 5781 else
5778 #endif 5782 #endif
5779 len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); 5783 len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK)
5784 #ifdef FEAT_PROP_POPUP
5785 - (long)textprop_total
5786 #endif
5787 ;
5780 size += len; 5788 size += len;
5781 if (offset != 0 && size >= offset) 5789 if (offset != 0 && size >= offset)
5782 { 5790 {
5783 if (size + ffdos == offset) 5791 if (size + ffdos == offset)
5784 *offp = 0; 5792 *offp = 0;
5785 else if (idx == start_idx) 5793 else if (idx == start_idx)
5786 *offp = offset - size + len; 5794 *offp = offset - size + len;
5787 else 5795 else
5788 *offp = offset - size + len 5796 *offp = offset - size + len
5789 - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); 5797 - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK))
5798 #ifdef FEAT_PROP_POPUP
5799 + (long)textprop_total
5800 #endif
5801 ;
5790 curline += idx - start_idx + extra; 5802 curline += idx - start_idx + extra;
5791 if (curline > buf->b_ml.ml_line_count) 5803 if (curline > buf->b_ml.ml_line_count)
5792 return -1; // exactly one byte beyond the end 5804 return -1; // exactly one byte beyond the end
5793 return curline; 5805 return curline;
5794 } 5806 }