vim-patch:8.2.5116: "limit" option of matchfuzzy() not always respected (#19005)

Problem:    "limit" option of matchfuzzy() not always respected.
Solution:   Remove "else". (Kazuyuki Miyagi, closes vim/vim#10586)
47f1a55849
This commit is contained in:
zeertzjq
2022-06-18 13:43:02 +08:00
committed by GitHub
parent e651ae5864
commit 966d55effe
3 changed files with 13 additions and 3 deletions

View File

@@ -5034,6 +5034,8 @@ matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
matchseq When this item is present return only matches matchseq When this item is present return only matches
that contain the characters in {str} in the that contain the characters in {str} in the
given sequence. given sequence.
limit Maximum number of matches in {list} to be
returned. Zero means no limit.
If {list} is a list of dictionaries, then the optional {dict} If {list} is a list of dictionaries, then the optional {dict}
argument supports the following additional items: argument supports the following additional items:
@@ -5045,8 +5047,6 @@ matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
This should accept a dictionary item as the This should accept a dictionary item as the
argument and return the text for that item to argument and return the text for that item to
use for fuzzy matching. use for fuzzy matching.
limit Maximum number of matches in {list} to be
returned. Zero means no limit.
{str} is treated as a literal string and regular expression {str} is treated as a literal string and regular expression
matching is NOT supported. The maximum supported {str} length matching is NOT supported. The maximum supported {str} length

View File

@@ -5239,7 +5239,9 @@ static void do_fuzzymatch(const typval_T *const argvars, typval_T *const rettv,
} else if (!tv_dict_get_callback(d, "text_cb", -1, &cb)) { } else if (!tv_dict_get_callback(d, "text_cb", -1, &cb)) {
semsg(_(e_invargval), "text_cb"); semsg(_(e_invargval), "text_cb");
return; return;
} else if ((di = tv_dict_find(d, "limit", -1)) != NULL) { }
if ((di = tv_dict_find(d, "limit", -1)) != NULL) {
if (di->di_tv.v_type != VAR_NUMBER) { if (di->di_tv.v_type != VAR_NUMBER) {
semsg(_(e_invarg2), tv_get_string(&di->di_tv)); semsg(_(e_invarg2), tv_get_string(&di->di_tv));
return; return;

View File

@@ -258,6 +258,14 @@ func Test_matchfuzzy_limit()
call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 2})) call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 2}))
call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 3})) call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 3}))
call assert_fails("call matchfuzzy(x, '2', #{limit: '2'})", 'E475:') call assert_fails("call matchfuzzy(x, '2', #{limit: '2'})", 'E475:')
let l = [{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}]
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}}))
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{key: 'val'}))
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}, limit: 0}))
call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{key: 'val', limit: 0}))
call assert_equal([{'id': 5, 'val': 'crayon'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}, limit: 1}))
call assert_equal([{'id': 5, 'val': 'crayon'}], l->matchfuzzy('c', #{key: 'val', limit: 1}))
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab