Patch 8.2.2667
Problem:    prop_find() cannot find item matching both id and type.
Solution:   Add the "both" argument. (Naohiro Ono, closes #8019)
Files:      runtime/doc/textprop.txt, src/testdir/test_textprop.vim,
            src/textprop.c


*** ../vim-8.2.2666/runtime/doc/textprop.txt    2021-01-31 17:02:06.262490144 
+0100
--- runtime/doc/textprop.txt    2021-03-27 22:04:42.438131529 +0100
***************
*** 175,180 ****
--- 175,181 ----
                Search for a text property as specified with {props}:
                   id           property with this ID
                   type         property with this type name
+                  both         "id" and "type" must both match
                   bufnr        buffer to search in; when present a
                                start position with "lnum" and "col"
                                must be given; when omitted the
***************
*** 187,192 ****
--- 188,194 ----
                   skipstart    do not look for a match at the start
                                position
  
+               A property matches when either "id" or "type" matches.
                {direction} can be "f" for forward and "b" for backward.  When
                omitted forward search is performed.
  
*** ../vim-8.2.2666/src/testdir/test_textprop.vim       2021-03-02 
13:36:44.249228358 +0100
--- src/testdir/test_textprop.vim       2021-03-27 22:04:42.438131529 +0100
***************
*** 245,250 ****
--- 245,269 ----
    call prop_type_delete('test')
  endfunc
  
+ func Test_prop_find_with_both_option_enabled()
+   " Initialize
+   new
+   call AddPropTypes()
+   call SetupPropsInFirstLine()
+   let props = Get_expected_props()->map({_, v -> extend(v, {'lnum': 1})})
+   " Test
+   call assert_fails("call prop_find({'both': 1})", 'E968:')
+   call assert_fails("call prop_find({'id': 11, 'both': 1})", 'E860:')
+   call assert_fails("call prop_find({'type': 'three', 'both': 1})", 'E860:')
+   call assert_equal({}, prop_find({'id': 11, 'type': 'three', 'both': 1}))
+   call assert_equal({}, prop_find({'id': 130000, 'type': 'one', 'both': 1}))
+   call assert_equal(props[2], prop_find({'id': 12, 'type': 'two', 'both': 1}))
+   call assert_equal(props[0], prop_find({'id': 14, 'type': 'whole', 'both': 
1}))
+   " Clean up
+   call DeletePropTypes()
+   bwipe!
+ endfunc
+ 
  func Test_prop_add()
    new
    call AddPropTypes()
*** ../vim-8.2.2666/src/textprop.c      2021-03-22 19:43:30.352211669 +0100
--- src/textprop.c      2021-03-27 22:04:42.438131529 +0100
***************
*** 600,605 ****
--- 600,606 ----
      int               lnum = -1;
      int               col = -1;
      int               dir = 1;    // 1 = forward, -1 = backward
+     int               both;
  
      if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
      {
***************
*** 661,671 ****
--- 662,678 ----
            return;
        type_id = type->pt_id;
      }
+     both = dict_get_bool(dict, (char_u *)"both", FALSE);
      if (id == -1 && type_id == -1)
      {
        emsg(_("E968: Need at least one of 'id' or 'type'"));
        return;
      }
+     if (both && (id == -1 || type_id == -1))
+     {
+       emsg(_("E860: Need 'id' and 'type' with 'both'"));
+       return;
+     }
  
      lnum_start = lnum;
  
***************
*** 698,704 ****
                else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
                    continue;
            }
!           if (prop.tp_id == id || prop.tp_type == type_id)
            {
                // Check if the starting position has text props.
                if (lnum_start == lnum
--- 705,712 ----
                else if (prop.tp_col + prop.tp_len - (prop.tp_len != 0) < col)
                    continue;
            }
!           if (both ? prop.tp_id == id && prop.tp_type == type_id
!                    : prop.tp_id == id || prop.tp_type == type_id)
            {
                // Check if the starting position has text props.
                if (lnum_start == lnum
*** ../vim-8.2.2666/src/version.c       2021-03-27 21:23:27.064153032 +0100
--- src/version.c       2021-03-27 22:06:36.301843564 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2667,
  /**/

-- 
'Well, here's something to occupy you and keep your mind off things.'
'It won't work, I have an exceptionally large mind.'
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202103272108.12RL85Mn701327%40masaka.moolenaar.net.

Raspunde prin e-mail lui