]> granicus.if.org Git - vim/commitdiff
patch 8.2.0372: prop_find() may not find text property at start of the line v8.2.0372
authorBram Moolenaar <Bram@vim.org>
Wed, 11 Mar 2020 18:15:52 +0000 (19:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 11 Mar 2020 18:15:52 +0000 (19:15 +0100)
Problem:    Prop_find() may not find text property at start of the line.
Solution:   Adjust the loop to find properties. (Axel Forsman, closes #5761,
            closes #5663)

src/testdir/test_textprop.vim
src/textprop.c
src/version.c

index 0f28f0d370046c158266b3eb9f1d06fcea25b020..6d3aaa3be0870c1e1f785eaf79964383b075ea5b 100644 (file)
@@ -1166,3 +1166,30 @@ func Test_textprop_ins_str()
   call prop_remove({'type': 'test'})
   call prop_type_delete('test')
 endfunc
+
+func Test_find_prop_later_in_line()
+  new
+  call prop_type_add('test', {'highlight': 'ErrorMsg'})
+  call setline(1, 'just some text')
+  call prop_add(1, 1, {'length': 4, 'type': 'test'})
+  call prop_add(1, 10, {'length': 3, 'type': 'test'})
+
+  call assert_equal({'id': 0, 'lnum': 1, 'col': 10, 'end': 1, 'type': 'test', 'length': 3, 'start': 1},
+                         \ prop_find(#{type: 'test', lnum: 1, col: 6}))
+
+  bwipe!
+  call prop_type_delete('test')
+endfunc
+
+func Test_find_zerowidth_prop_sol()
+  new
+  call prop_type_add('test', {'highlight': 'ErrorMsg'})
+  call setline(1, 'just some text')
+  call prop_add(1, 1, {'length': 0, 'type': 'test'})
+
+  call assert_equal({'id': 0, 'lnum': 1, 'col': 1, 'end': 1, 'type': 'test', 'length': 0, 'start': 1},
+                         \ prop_find(#{type: 'test', lnum: 1}))
+
+  bwipe!
+  call prop_type_delete('test')
+endfunc
index 2827af437b7efcefd4b084ecb42695788e79fc41..4f5329ebb1fb23c7dbdd50659ae2cd103c973146 100644 (file)
@@ -663,24 +663,22 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
            mch_memmove(&prop, text + textlen + i * sizeof(textprop_T),
                            sizeof(textprop_T));
 
+           if (dir < 0)
+           {
+               if (col < prop.tp_col)
+                   break;
+           }
+           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)
-               {
-                   if (col >= prop.tp_col
-                                      && (col <= prop.tp_col + prop.tp_len-1))
-                       start_pos_has_prop = 1;
-               }
-               else
-               {
-                   // Not at the first line of the search so adjust col to
-                   // indicate that we're continuing from prev/next line.
-                   if (dir < 0)
-                       col = buf->b_ml.ml_line_len;
-                   else
-                       col = 1;
-               }
+               if (lnum_start == lnum
+                       && col >= prop.tp_col
+                       && (col <= prop.tp_col + prop.tp_len
+                                                        - (prop.tp_len != 0)))
+                   start_pos_has_prop = 1;
 
                prop_start = !(prop.tp_flags & TP_FLAG_CONT_PREV);
                prop_end = !(prop.tp_flags & TP_FLAG_CONT_NEXT);
@@ -705,17 +703,6 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
                    break;
                }
 
-               if (dir < 0)
-               {
-                   if (col < prop.tp_col)
-                       break;
-               }
-               else
-               {
-                   if (col > prop.tp_col + prop.tp_len-1)
-                       break;
-               }
-
                prop_fill_dict(rettv->vval.v_dict, &prop, buf);
                dict_add_number(rettv->vval.v_dict, "lnum", lnum);
 
@@ -735,6 +722,8 @@ f_prop_find(typval_T *argvars, typval_T *rettv)
                break;
            lnum--;
        }
+       // Adjust col to indicate that we're continuing from prev/next line.
+       col = dir < 0 ? buf->b_ml.ml_line_len : 1;
     }
 }
 
index eb76880dc92edd5028c36f5a7189f549f5177f55..2bf4b24aa4a6e55d1aa20db8b055fa6871e7011a 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    372,
 /**/
     371,
 /**/