mirror of
https://github.com/vim/vim.git
synced 2025-10-08 06:04:08 -04:00
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)
This commit is contained in:
@@ -5752,13 +5752,38 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef FEAT_PROP_POPUP
|
||||||
|
long textprop_total = 0;
|
||||||
|
long textprop_size = 0;
|
||||||
|
char_u *l1, *l2;
|
||||||
|
#endif
|
||||||
|
|
||||||
extra = 0;
|
extra = 0;
|
||||||
while (offset >= size
|
for (;;)
|
||||||
+ text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
|
|
||||||
+ ffdos)
|
|
||||||
{
|
{
|
||||||
|
#ifdef FEAT_PROP_POPUP
|
||||||
|
if (buf->b_has_textprop)
|
||||||
|
{
|
||||||
|
// compensate for the extra bytes taken by textprops
|
||||||
|
l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK);
|
||||||
|
l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end
|
||||||
|
: ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
|
||||||
|
textprop_size = (l2 - l1) - (STRLEN(l1) + 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!(offset >= size
|
||||||
|
+ text_end - (int)((dp->db_index[idx]) & DB_INDEX_MASK)
|
||||||
|
#ifdef FEAT_PROP_POPUP
|
||||||
|
- textprop_total - textprop_size
|
||||||
|
#endif
|
||||||
|
+ ffdos))
|
||||||
|
break;
|
||||||
|
|
||||||
if (ffdos)
|
if (ffdos)
|
||||||
size++;
|
size++;
|
||||||
|
#ifdef FEAT_PROP_POPUP
|
||||||
|
textprop_total += textprop_size;
|
||||||
|
#endif
|
||||||
if (idx == count - 1)
|
if (idx == count - 1)
|
||||||
{
|
{
|
||||||
extra = 1;
|
extra = 1;
|
||||||
@@ -5776,7 +5801,8 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
|
|||||||
// lengths.
|
// lengths.
|
||||||
len = 0;
|
len = 0;
|
||||||
for (i = start_idx; i <= idx; ++i)
|
for (i = start_idx; i <= idx; ++i)
|
||||||
len += (int)STRLEN((char_u *)dp + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1;
|
len += (int)STRLEN((char_u *)dp
|
||||||
|
+ ((dp->db_index[i]) & DB_INDEX_MASK)) + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@@ -664,7 +664,7 @@ func Test_prop_multiline()
|
|||||||
call prop_type_delete('comment')
|
call prop_type_delete('comment')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_prop_byteoff()
|
func Test_prop_line2byte()
|
||||||
call prop_type_add('comment', {'highlight': 'Directory'})
|
call prop_type_add('comment', {'highlight': 'Directory'})
|
||||||
new
|
new
|
||||||
call setline(1, ['line1', 'second line', ''])
|
call setline(1, ['line1', 'second line', ''])
|
||||||
@@ -677,6 +677,22 @@ func Test_prop_byteoff()
|
|||||||
call prop_type_delete('comment')
|
call prop_type_delete('comment')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_prop_byte2line()
|
||||||
|
new
|
||||||
|
set ff=unix
|
||||||
|
call setline(1, ['one one', 'two two', 'three three', 'four four', 'five'])
|
||||||
|
call assert_equal(4, byte2line(line2byte(4)))
|
||||||
|
call assert_equal(5, byte2line(line2byte(5)))
|
||||||
|
|
||||||
|
call prop_type_add('prop', {'highlight': 'Directory'})
|
||||||
|
call prop_add(3, 1, {'length': 5, 'type': 'prop'})
|
||||||
|
call assert_equal(4, byte2line(line2byte(4)))
|
||||||
|
call assert_equal(5, byte2line(line2byte(5)))
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
call prop_type_delete('prop')
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_prop_undo()
|
func Test_prop_undo()
|
||||||
new
|
new
|
||||||
call prop_type_add('comment', {'highlight': 'Directory'})
|
call prop_type_add('comment', {'highlight': 'Directory'})
|
||||||
|
@@ -742,6 +742,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
115,
|
||||||
/**/
|
/**/
|
||||||
114,
|
114,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user