Mercurial > vim
comparison src/memline.c @ 25624:0ef8ef1af478 v8.2.3348
patch 8.2.3348: line2byte() returns wrong value after adding textprop
Commit: https://github.com/vim/vim/commit/14c7530c4fca786d3594508e28943f10125827c3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 15 14:28:40 2021 +0200
patch 8.2.3348: line2byte() returns wrong value after adding textprop
Problem: line2byte() returns wrong value after adding textprop. (Yuto
Kimura)
Solution: Reduce the length by the size of the text property. (closes #8759)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 15 Aug 2021 14:30:04 +0200 |
parents | 1919361a53da |
children | 885fba352580 |
comparison
equal
deleted
inserted
replaced
25623:6d259614c0f4 | 25624:0ef8ef1af478 |
---|---|
3975 /* | 3975 /* |
3976 * if new line fits in data block, replace directly | 3976 * if new line fits in data block, replace directly |
3977 */ | 3977 */ |
3978 if ((int)dp->db_free >= extra) | 3978 if ((int)dp->db_free >= extra) |
3979 { | 3979 { |
3980 #ifdef FEAT_BYTEOFF | |
3981 int old_prop_len = 0; | |
3982 #endif | |
3980 // if the length changes and there are following lines | 3983 // if the length changes and there are following lines |
3981 count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; | 3984 count = buf->b_ml.ml_locked_high - buf->b_ml.ml_locked_low + 1; |
3982 if (extra != 0 && idx < count - 1) | 3985 if (extra != 0 && idx < count - 1) |
3983 { | 3986 { |
3984 // move text of following lines | 3987 // move text of following lines |
3993 dp->db_index[idx] -= extra; | 3996 dp->db_index[idx] -= extra; |
3994 | 3997 |
3995 // adjust free space | 3998 // adjust free space |
3996 dp->db_free -= extra; | 3999 dp->db_free -= extra; |
3997 dp->db_txt_start -= extra; | 4000 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 | |
3998 | 4005 |
3999 // copy new line into the data block | 4006 // copy new line into the data block |
4000 mch_memmove(old_line - extra, new_line, (size_t)new_len); | 4007 mch_memmove(old_line - extra, new_line, (size_t)new_len); |
4001 buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); | 4008 buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); |
4002 #ifdef FEAT_BYTEOFF | 4009 #ifdef FEAT_BYTEOFF |
4003 // The else case is already covered by the insert and delete | 4010 // 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); | |
4005 #endif | 4019 #endif |
4006 } | 4020 } |
4007 else | 4021 else |
4008 { | 4022 { |
4009 /* | 4023 /* |
5593 size += (int)STRLEN((char_u *)dp + (dp->db_index[i] & DB_INDEX_MASK)) + 1; | 5607 size += (int)STRLEN((char_u *)dp + (dp->db_index[i] & DB_INDEX_MASK)) + 1; |
5594 } | 5608 } |
5595 else | 5609 else |
5596 #endif | 5610 #endif |
5597 { | 5611 { |
5598 if (idx == 0)// first line in block, text at the end | 5612 if (idx == 0) // first line in block, text at the end |
5599 text_end = dp->db_txt_end; | 5613 text_end = dp->db_txt_end; |
5600 else | 5614 else |
5601 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); | 5615 text_end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); |
5602 size += text_end - ((dp->db_index[end_idx]) & DB_INDEX_MASK); | 5616 size += text_end - ((dp->db_index[end_idx]) & DB_INDEX_MASK); |
5603 } | 5617 } |
5732 offset = *offp; | 5746 offset = *offp; |
5733 if (lnum == 0 && offset <= 0) | 5747 if (lnum == 0 && offset <= 0) |
5734 return 1; // Not a "find offset" and offset 0 _must_ be in line 1 | 5748 return 1; // Not a "find offset" and offset 0 _must_ be in line 1 |
5735 /* | 5749 /* |
5736 * Find the last chunk before the one containing our line. Last chunk is | 5750 * 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. |
5738 */ | 5752 */ |
5739 curline = 1; | 5753 curline = 1; |
5740 curix = size = 0; | 5754 curix = size = 0; |
5741 while (curix < buf->b_ml.ml_usedchunks - 1 | 5755 while (curix < buf->b_ml.ml_usedchunks - 1 |
5742 && ((lnum != 0 | 5756 && ((lnum != 0 |