Skip to content

Commit 8507747

Browse files
committed
patch 8.0.0040
Problem: Whole line highlighting with matchaddpos() does not work. Solution: Check for zero length. (Hirohito Higashi)
1 parent 156919f commit 8507747

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

src/screen.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7773,6 +7773,10 @@ next_search_hl(
77737773
}
77747774
}
77757775

7776+
/*
7777+
* If there is a match fill "shl" and return one.
7778+
* Return zero otherwise.
7779+
*/
77767780
static int
77777781
next_search_hl_pos(
77787782
match_T *shl, /* points to a match */
@@ -7781,55 +7785,52 @@ next_search_hl_pos(
77817785
colnr_T mincol) /* minimal column for a match */
77827786
{
77837787
int i;
7784-
int bot = -1;
7788+
int found = -1;
77857789

7786-
shl->lnum = 0;
77877790
for (i = posmatch->cur; i < MAXPOSMATCH; i++)
77887791
{
77897792
llpos_T *pos = &posmatch->pos[i];
77907793

77917794
if (pos->lnum == 0)
77927795
break;
7793-
if (pos->col + pos->len - 1 <= mincol)
7796+
if (pos->len == 0 && pos->col < mincol)
77947797
continue;
77957798
if (pos->lnum == lnum)
77967799
{
7797-
if (shl->lnum == lnum)
7800+
if (found >= 0)
77987801
{
7799-
/* partially sort positions by column numbers
7800-
* on the same line */
7801-
if (pos->col < posmatch->pos[bot].col)
7802+
/* if this match comes before the one at "found" then swap
7803+
* them */
7804+
if (pos->col < posmatch->pos[found].col)
78027805
{
78037806
llpos_T tmp = *pos;
78047807

7805-
*pos = posmatch->pos[bot];
7806-
posmatch->pos[bot] = tmp;
7808+
*pos = posmatch->pos[found];
7809+
posmatch->pos[found] = tmp;
78077810
}
78087811
}
78097812
else
7810-
{
7811-
bot = i;
7812-
shl->lnum = lnum;
7813-
}
7813+
found = i;
78147814
}
78157815
}
78167816
posmatch->cur = 0;
7817-
if (shl->lnum == lnum && bot >= 0)
7817+
if (found >= 0)
78187818
{
7819-
colnr_T start = posmatch->pos[bot].col == 0
7820-
? 0 : posmatch->pos[bot].col - 1;
7821-
colnr_T end = posmatch->pos[bot].col == 0
7822-
? MAXCOL : start + posmatch->pos[bot].len;
7819+
colnr_T start = posmatch->pos[found].col == 0
7820+
? 0 : posmatch->pos[found].col - 1;
7821+
colnr_T end = posmatch->pos[found].col == 0
7822+
? MAXCOL : start + posmatch->pos[found].len;
78237823

7824+
shl->lnum = lnum;
78247825
shl->rm.startpos[0].lnum = 0;
78257826
shl->rm.startpos[0].col = start;
78267827
shl->rm.endpos[0].lnum = 0;
78277828
shl->rm.endpos[0].col = end;
78287829
shl->is_addpos = TRUE;
7829-
posmatch->cur = bot + 1;
7830-
return TRUE;
7830+
posmatch->cur = found + 1;
7831+
return 1;
78317832
}
7832-
return FALSE;
7833+
return 0;
78337834
}
78347835
#endif
78357836

src/testdir/test_match.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,15 @@ func Test_matchaddpos()
191191
call assert_equal(screenattr(2,2), screenattr(1,7))
192192
call assert_notequal(screenattr(2,2), screenattr(1,8))
193193

194+
call clearmatches()
195+
call matchaddpos('Error', [[1], [2,2]])
196+
redraw!
197+
call assert_equal(screenattr(2,2), screenattr(1,1))
198+
call assert_equal(screenattr(2,2), screenattr(1,10))
199+
call assert_notequal(screenattr(2,2), screenattr(1,11))
200+
194201
nohl
202+
call clearmatches()
195203
syntax off
196204
set hlsearch&
197205
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
40,
767769
/**/
768770
39,
769771
/**/

0 commit comments

Comments
 (0)