Mercurial > vim
comparison src/memline.c @ 19110:e40814841406 v8.2.0115
patch 8.2.0115: byte2line() does not work correctly with text properties
Commit: https://github.com/vim/vim/commit/9df53b62de86f544b41bef5e964b7fc8ae5231e3
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 13 20:40:51 2020 +0100
patch 8.2.0115: byte2line() does not work correctly with text properties
Problem: Byte2line() does not work correctly with text properties. (Billie
Cleek)
Solution: Take the bytes of the text properties into account.
(closes #5334)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 13 Jan 2020 20:45:03 +0100 |
parents | f41b55f9357c |
children | d7664581988e |
comparison
equal
deleted
inserted
replaced
19109:a25bb65cb6d8 | 19110:e40814841406 |
---|---|
5736 return -1; | 5736 return -1; |
5737 dp = (DATA_BL *)(hp->bh_data); | 5737 dp = (DATA_BL *)(hp->bh_data); |
5738 count = (long)(buf->b_ml.ml_locked_high) - | 5738 count = (long)(buf->b_ml.ml_locked_high) - |
5739 (long)(buf->b_ml.ml_locked_low) + 1; | 5739 (long)(buf->b_ml.ml_locked_low) + 1; |
5740 start_idx = idx = curline - buf->b_ml.ml_locked_low; | 5740 start_idx = idx = curline - buf->b_ml.ml_locked_low; |
5741 if (idx == 0)// first line in block, text at the end | 5741 if (idx == 0) // first line in block, text at the end |
5742 text_end = dp->db_txt_end; | 5742 text_end = dp->db_txt_end; |
5743 else | 5743 else |
5744 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); | 5744 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); |
5745 // Compute index of last line to use in this MEMLINE | 5745 // Compute index of last line to use in this MEMLINE |
5746 if (lnum != 0) | 5746 if (lnum != 0) |
5750 else | 5750 else |
5751 idx = count - 1; | 5751 idx = count - 1; |
5752 } | 5752 } |
5753 else | 5753 else |
5754 { | 5754 { |
5755 #ifdef FEAT_PROP_POPUP | |
5756 long textprop_total = 0; | |
5757 long textprop_size = 0; | |
5758 char_u *l1, *l2; | |
5759 #endif | |
5760 | |
5755 extra = 0; | 5761 extra = 0; |
5756 while (offset >= size | 5762 for (;;) |
5757 + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK) | |
5758 + ffdos) | |
5759 { | 5763 { |
5764 #ifdef FEAT_PROP_POPUP | |
5765 if (buf->b_has_textprop) | |
5766 { | |
5767 // compensate for the extra bytes taken by textprops | |
5768 l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK); | |
5769 l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end | |
5770 : ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); | |
5771 textprop_size = (l2 - l1) - (STRLEN(l1) + 1); | |
5772 } | |
5773 #endif | |
5774 if (!(offset >= size | |
5775 + text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK) | |
5776 #ifdef FEAT_PROP_POPUP | |
5777 - textprop_total - textprop_size | |
5778 #endif | |
5779 + ffdos)) | |
5780 break; | |
5781 | |
5760 if (ffdos) | 5782 if (ffdos) |
5761 size++; | 5783 size++; |
5784 #ifdef FEAT_PROP_POPUP | |
5785 textprop_total += textprop_size; | |
5786 #endif | |
5762 if (idx == count - 1) | 5787 if (idx == count - 1) |
5763 { | 5788 { |
5764 extra = 1; | 5789 extra = 1; |
5765 break; | 5790 break; |
5766 } | 5791 } |
5774 | 5799 |
5775 // cannot use the db_index pointer, need to get the actual text | 5800 // cannot use the db_index pointer, need to get the actual text |
5776 // lengths. | 5801 // lengths. |
5777 len = 0; | 5802 len = 0; |
5778 for (i = start_idx; i <= idx; ++i) | 5803 for (i = start_idx; i <= idx; ++i) |
5779 len += (int)STRLEN((char_u *)dp + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1; | 5804 len += (int)STRLEN((char_u *)dp |
5805 + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1; | |
5780 } | 5806 } |
5781 else | 5807 else |
5782 #endif | 5808 #endif |
5783 len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); | 5809 len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); |
5784 size += len; | 5810 size += len; |