Skip to content

Commit 66b9885

Browse files
committed
patch 8.2.0372: prop_find() may not find text property at start of the line
Problem: Prop_find() may not find text property at start of the line. Solution: Adjust the loop to find properties. (Axel Forsman, closes #5761, closes #5663)
1 parent cee5220 commit 66b9885

3 files changed

Lines changed: 44 additions & 26 deletions

File tree

src/testdir/test_textprop.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,3 +1166,30 @@ func Test_textprop_ins_str()
11661166
call prop_remove({'type': 'test'})
11671167
call prop_type_delete('test')
11681168
endfunc
1169+
1170+
func Test_find_prop_later_in_line()
1171+
new
1172+
call prop_type_add('test', {'highlight': 'ErrorMsg'})
1173+
call setline(1, 'just some text')
1174+
call prop_add(1, 1, {'length': 4, 'type': 'test'})
1175+
call prop_add(1, 10, {'length': 3, 'type': 'test'})
1176+
1177+
call assert_equal({'id': 0, 'lnum': 1, 'col': 10, 'end': 1, 'type': 'test', 'length': 3, 'start': 1},
1178+
\ prop_find(#{type: 'test', lnum: 1, col: 6}))
1179+
1180+
bwipe!
1181+
call prop_type_delete('test')
1182+
endfunc
1183+
1184+
func Test_find_zerowidth_prop_sol()
1185+
new
1186+
call prop_type_add('test', {'highlight': 'ErrorMsg'})
1187+
call setline(1, 'just some text')
1188+
call prop_add(1, 1, {'length': 0, 'type': 'test'})
1189+
1190+
call assert_equal({'id': 0, 'lnum': 1, 'col': 1, 'end': 1, 'type': 'test', 'length': 0, 'start': 1},
1191+
\ prop_find(#{type: 'test', lnum: 1}))
1192+
1193+
bwipe!
1194+
call prop_type_delete('test')
1195+
endfunc

src/textprop.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -663,24 +663,22 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
663663
mch_memmove(&prop, text + textlen + i * sizeof(textprop_T),
664664
sizeof(textprop_T));
665665

666+
if (dir < 0)
667+
{
668+
if (col < prop.tp_col)
669+
break;
670+
}
671+
else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
672+
continue;
673+
666674
if (prop.tp_id == id || prop.tp_type == type_id)
667675
{
668676
// Check if the starting position has text props.
669-
if (lnum_start == lnum)
670-
{
671-
if (col >= prop.tp_col
672-
&& (col <= prop.tp_col + prop.tp_len-1))
673-
start_pos_has_prop = 1;
674-
}
675-
else
676-
{
677-
// Not at the first line of the search so adjust col to
678-
// indicate that we're continuing from prev/next line.
679-
if (dir < 0)
680-
col = buf->b_ml.ml_line_len;
681-
else
682-
col = 1;
683-
}
677+
if (lnum_start == lnum
678+
&& col >= prop.tp_col
679+
&& (col <= prop.tp_col + prop.tp_len
680+
- (prop.tp_len != 0)))
681+
start_pos_has_prop = 1;
684682

685683
prop_start = !(prop.tp_flags & TP_FLAG_CONT_PREV);
686684
prop_end = !(prop.tp_flags & TP_FLAG_CONT_NEXT);
@@ -705,17 +703,6 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
705703
break;
706704
}
707705

708-
if (dir < 0)
709-
{
710-
if (col < prop.tp_col)
711-
break;
712-
}
713-
else
714-
{
715-
if (col > prop.tp_col + prop.tp_len-1)
716-
break;
717-
}
718-
719706
prop_fill_dict(rettv->vval.v_dict, &prop, buf);
720707
dict_add_number(rettv->vval.v_dict, "lnum", lnum);
721708

@@ -735,6 +722,8 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
735722
break;
736723
lnum--;
737724
}
725+
// Adjust col to indicate that we're continuing from prev/next line.
726+
col = dir < 0 ? buf->b_ml.ml_line_len : 1;
738727
}
739728
}
740729

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
372,
741743
/**/
742744
371,
743745
/**/

0 commit comments

Comments
 (0)