]> granicus.if.org Git - vim/commitdiff
patch 8.2.5116: "limit" option of matchfuzzy() not always respected v8.2.5116
authorKazuyuki Miyagi <yuzu3886@gmail.com>
Fri, 17 Jun 2022 17:30:03 +0000 (18:30 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 17 Jun 2022 17:30:03 +0000 (18:30 +0100)
Problem:    "limit" option of matchfuzzy() not always respected.
Solution:   Remove "else". (Kazuyuki Miyagi, closes #10586)

runtime/doc/builtin.txt
src/search.c
src/testdir/test_matchfuzzy.vim
src/version.c

index 455fd968057f36cb9da0e37d3c6fa42b8fb7d425..f0c1ddc1b303f0951aede2e525589f1ca25ca2f3 100644 (file)
@@ -5899,6 +5899,8 @@ matchfuzzy({list}, {str} [, {dict}])                      *matchfuzzy()*
                    matchseq    When this item is present return only matches
                                that contain the characters in {str} in the
                                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}
                argument supports the following additional items:
@@ -5910,8 +5912,6 @@ matchfuzzy({list}, {str} [, {dict}])                      *matchfuzzy()*
                                This should accept a dictionary item as the
                                argument and return the text for that item to
                                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
                matching is NOT supported.  The maximum supported {str} length
index e78e36b1ed9a8b5cf640c79c1aa92a59fd980d06..c7309ee6340fa13398b0d7ee6b53ef368393970a 100644 (file)
@@ -4844,7 +4844,8 @@ do_fuzzymatch(typval_T *argvars, typval_T *rettv, int retmatchpos)
                return;
            }
        }
-       else if ((di = dict_find(d, (char_u *)"limit", -1)) != NULL)
+
+       if ((di = dict_find(d, (char_u *)"limit", -1)) != NULL)
        {
            if (di->di_tv.v_type != VAR_NUMBER)
            {
index b397392a763b9d5590eeeccf6d15899f113b8251..02a74469e092acbe34fe7006271c1bc9ea51398e 100644 (file)
@@ -243,6 +243,14 @@ func Test_matchfuzzy_limit()
   call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 2}))
   call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 3}))
   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
 
 " vim: shiftwidth=2 sts=2 expandtab
index a7e622eab3d5868c46c9180f27fb2f2ae796005a..c842e19ddef26bd279c4d731eb16a20f6ae9f774 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5116,
 /**/
     5115,
 /**/