Skip to content

Commit 24f21fd

Browse files
committed
patch 8.2.2667: prop_find() cannot find item matching both id and type
Problem: prop_find() cannot find item matching both id and type. Solution: Add the "both" argument. (Naohiro Ono, closes #8019)
1 parent c580943 commit 24f21fd

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

runtime/doc/textprop.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ prop_find({props} [, {direction}])
175175
Search for a text property as specified with {props}:
176176
id property with this ID
177177
type property with this type name
178+
both "id" and "type" must both match
178179
bufnr buffer to search in; when present a
179180
start position with "lnum" and "col"
180181
must be given; when omitted the
@@ -187,6 +188,7 @@ prop_find({props} [, {direction}])
187188
skipstart do not look for a match at the start
188189
position
189190

191+
A property matches when either "id" or "type" matches.
190192
{direction} can be "f" for forward and "b" for backward. When
191193
omitted forward search is performed.
192194

src/testdir/test_textprop.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ func Test_prop_find_smaller_len_than_match_col()
245245
call prop_type_delete('test')
246246
endfunc
247247

248+
func Test_prop_find_with_both_option_enabled()
249+
" Initialize
250+
new
251+
call AddPropTypes()
252+
call SetupPropsInFirstLine()
253+
let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})})
254+
" Test
255+
call assert_fails("call prop_find({'both': 1})", 'E968:')
256+
call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:')
257+
call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:')
258+
call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1}))
259+
call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1}))
260+
call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1}))
261+
call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 1}))
262+
" Clean up
263+
call DeletePropTypes()
264+
bwipe!
265+
endfunc
266+
248267
func Test_prop_add()
249268
new
250269
call AddPropTypes()

src/textprop.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
600600
int lnum = -1;
601601
int col = -1;
602602
int dir = 1; // 1 = forward, -1 = backward
603+
int both;
603604

604605
if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
605606
{
@@ -661,11 +662,17 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
661662
return;
662663
type_id = type->pt_id;
663664
}
665+
both = dict_get_bool(dict, (char_u *)"both", FALSE);
664666
if (id == -1 && type_id == -1)
665667
{
666668
emsg(_("E968: Need at least one of 'id' or 'type'"));
667669
return;
668670
}
671+
if (both && (id == -1 || type_id == -1))
672+
{
673+
emsg(_("E860: Need 'id' and 'type' with 'both'"));
674+
return;
675+
}
669676

670677
lnum_start = lnum;
671678

@@ -698,7 +705,8 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
698705
else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
699706
continue;
700707
}
701-
if (prop.tp_id == id || prop.tp_type == type_id)
708+
if (both ? prop.tp_id == id && prop.tp_type == type_id
709+
: prop.tp_id == id || prop.tp_type == type_id)
702710
{
703711
// Check if the starting position has text props.
704712
if (lnum_start == lnum

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2667,
753755
/**/
754756
2666,
755757
/**/

0 commit comments

Comments
 (0)