summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-03-11 19:15:52 +0100
committerBram Moolenaar <Bram@vim.org>2020-03-11 19:15:52 +0100
commit66b98854d86f641db036fd1e6cf20f7b8905344e (patch)
tree4d6f66d220b64b10c4dffe2d03acd5b46b001086
parentcee52204ca030ce7814844e4dab8b4ed897ba3cc (diff)
downloadvim-git-66b98854d86f641db036fd1e6cf20f7b8905344e.tar.gz
patch 8.2.0372: prop_find() may not find text property at start of the linev8.2.0372
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)
-rw-r--r--src/testdir/test_textprop.vim27
-rw-r--r--src/textprop.c41
-rw-r--r--src/version.c2
3 files changed, 44 insertions, 26 deletions
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 0f28f0d37..6d3aaa3be 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -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
diff --git a/src/textprop.c b/src/textprop.c
index 2827af437..4f5329ebb 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -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;
}
}
diff --git a/src/version.c b/src/version.c
index eb76880dc..2bf4b24aa 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 372,
+/**/
371,
/**/
370,