summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-30 17:16:28 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-30 17:16:28 +0100
commit59ff64079b4fcf0393a7413e3242a8b58c2ceadb (patch)
treea208fde9c4088bd4aa17ffd7bdafded18bb4aa69 /src
parent92e5df804719d2e6cb8145c2b098aa8d6f3dd252 (diff)
patch 8.2.2429: :goto does not work correctly with text propertiesv8.2.2429
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)
Diffstat (limited to 'src')
-rw-r--r--src/memline.c34
-rw-r--r--src/testdir/test_textprop.vim30
-rw-r--r--src/version.c2
3 files changed, 55 insertions, 11 deletions
diff --git a/src/memline.c b/src/memline.c
index 4137a66ad8..c5303bb837 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -5701,6 +5701,10 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
while ((lnum != 0 && curline < lnum) || (offset != 0 && size < offset))
{
+#ifdef FEAT_PROP_POPUP
+ size_t textprop_total = 0;
+#endif
+
if (curline > buf->b_ml.ml_line_count
|| (hp = ml_find_line(buf, curline, ML_FIND)) == NULL)
return -1;
@@ -5722,18 +5726,16 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
}
else
{
-#ifdef FEAT_PROP_POPUP
- size_t textprop_total = 0;
- size_t textprop_size = 0;
- char_u *l1, *l2;
-#endif
-
extra = 0;
for (;;)
{
#ifdef FEAT_PROP_POPUP
+ size_t textprop_size = 0;
+
if (buf->b_has_textprop)
{
+ char_u *l1, *l2;
+
// 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
@@ -5763,7 +5765,7 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
}
}
#ifdef FEAT_PROP_POPUP
- if (buf->b_has_textprop)
+ if (buf->b_has_textprop && lnum != 0)
{
int i;
@@ -5771,12 +5773,18 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
// lengths.
len = 0;
for (i = start_idx; i <= idx; ++i)
- len += (int)STRLEN((char_u *)dp
- + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1;
+ {
+ char_u *p = (char_u *)dp + ((dp->db_index[i]) & DB_INDEX_MASK);
+ len += (int)STRLEN(p) + 1;
+ }
}
else
#endif
- len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK);
+ len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK)
+#ifdef FEAT_PROP_POPUP
+ - (long)textprop_total
+#endif
+ ;
size += len;
if (offset != 0 && size >= offset)
{
@@ -5786,7 +5794,11 @@ ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
*offp = offset - size + len;
else
*offp = offset - size + len
- - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK));
+ - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK))
+#ifdef FEAT_PROP_POPUP
+ + (long)textprop_total
+#endif
+ ;
curline += idx - start_idx + extra;
if (curline > buf->b_ml.ml_line_count)
return -1; // exactly one byte beyond the end
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index a4033fa48b..245533567f 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -771,6 +771,36 @@ func Test_prop_byte2line()
call prop_type_delete('prop')
endfunc
+func Test_prop_goto_byte()
+ new
+ call setline(1, '')
+ call setline(2, 'two three')
+ call setline(3, '')
+ call setline(4, 'four five')
+
+ call prop_type_add('testprop', {'highlight': 'Directory'})
+ call search('^two')
+ call prop_add(line('.'), col('.'), {
+ \ 'length': len('two'),
+ \ 'type': 'testprop'
+ \ })
+
+ call search('two \zsthree')
+ let expected_pos = line2byte(line('.')) + col('.') - 1
+ exe expected_pos .. 'goto'
+ let actual_pos = line2byte(line('.')) + col('.') - 1
+ eval actual_pos->assert_equal(expected_pos)
+
+ call search('four \zsfive')
+ let expected_pos = line2byte(line('.')) + col('.') - 1
+ exe expected_pos .. 'goto'
+ let actual_pos = line2byte(line('.')) + col('.') - 1
+ eval actual_pos->assert_equal(expected_pos)
+
+ call prop_type_delete('testprop')
+ bwipe!
+endfunc
+
func Test_prop_undo()
new
call prop_type_add('comment', {'highlight': 'Directory'})
diff --git a/src/version.c b/src/version.c
index f7e267f030..52fa663997 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2429,
+/**/
2428,
/**/
2427,