]> granicus.if.org Git - vim/commitdiff
patch 8.2.0357: cannot delete a text property matching both id and type v8.2.0357
authorBram Moolenaar <Bram@vim.org>
Thu, 5 Mar 2020 20:52:55 +0000 (21:52 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 5 Mar 2020 20:52:55 +0000 (21:52 +0100)
Problem:    Cannot delete a text property matching both id and type. (Axel
            Forsman)
Solution:   Add the "both" argument.

runtime/doc/textprop.txt
src/testdir/test_textprop.vim
src/textprop.c
src/version.c

index 6dc58b70764e3082da6bdbf75f7594e6563081f7..55a5ed300baf6237fb6dbbbebd1c9b0058906e9b 100644 (file)
@@ -231,6 +231,7 @@ prop_remove({props} [, {lnum} [, {lnum-end}]])
                {props} is a dictionary with these fields:
                   id           remove text properties with this ID
                   type         remove text properties with this type name
+                  both         "id" and "type" must both match
                   bufnr        use this buffer instead of the current one
                   all          when TRUE remove all matching text properties,
                                not just the first one
index 6dbaa5350f86c04f4198536ffb13fa65d791852f..0f28f0d370046c158266b3eb9f1d06fcea25b020 100644 (file)
@@ -270,6 +270,23 @@ func Test_prop_remove()
 
   call DeletePropTypes()
   bwipe!
+
+  new
+  call AddPropTypes()
+  call SetupPropsInFirstLine()
+  call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
+  let props = Get_expected_props()
+  call insert(props, {'col': 6, 'length': 2, 'id': 11, 'type': 'three', 'start': 1, 'end': 1}, 3)
+  call assert_equal(props, prop_list(1))
+  call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
+  unlet props[3]
+  call assert_equal(props, prop_list(1))
+
+  call assert_fails("call prop_remove({'id': 11, 'both': 1})", 'E860')
+  call assert_fails("call prop_remove({'type': 'three', 'both': 1})", 'E860')
+
+  call DeletePropTypes()
+  bwipe!
 endfunc
 
 func SetupOneLine()
index 3ad84a24245411b3aea7bb50f0fd943a7335c5ba..2827af437b7efcefd4b084ecb42695788e79fc41 100644 (file)
@@ -796,6 +796,7 @@ f_prop_remove(typval_T *argvars, typval_T *rettv)
     int                do_all = FALSE;
     int                id = -1;
     int                type_id = -1;
+    int                both = FALSE;
 
     rettv->vval.v_number = 0;
     if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
@@ -838,11 +839,18 @@ f_prop_remove(typval_T *argvars, typval_T *rettv)
            return;
        type_id = type->pt_id;
     }
+    if (dict_find(dict, (char_u *)"both", -1) != NULL)
+       both = dict_get_number(dict, (char_u *)"both");
     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;
+    }
 
     if (end == 0)
        end = buf->b_ml.ml_line_count;
@@ -868,7 +876,8 @@ f_prop_remove(typval_T *argvars, typval_T *rettv)
                size_t  taillen;
 
                mch_memmove(&textprop, cur_prop, sizeof(textprop_T));
-               if (textprop.tp_id == id || textprop.tp_type == type_id)
+               if (both ? textprop.tp_id == id && textprop.tp_type == type_id
+                        : textprop.tp_id == id || textprop.tp_type == type_id)
                {
                    if (!(buf->b_ml.ml_flags & ML_LINE_DIRTY))
                    {
index 3e7115ba30d8d9b605433ed83f7fc39544e6f36a..2e3b729aa1bb92d62ac118009bcc604f879f5f79 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    357,
 /**/
     356,
 /**/