0
0
mirror of https://github.com/vim/vim.git synced 2025-10-02 05:04:20 -04:00

patch 8.0.0040

Problem:    Whole line highlighting with matchaddpos() does not work.
Solution:   Check for zero length. (Hirohito Higashi)
This commit is contained in:
Bram Moolenaar
2016-10-16 14:35:48 +02:00
parent 156919f99a
commit 8507747600
3 changed files with 32 additions and 21 deletions

View File

@@ -7773,6 +7773,10 @@ next_search_hl(
} }
} }
/*
* If there is a match fill "shl" and return one.
* Return zero otherwise.
*/
static int static int
next_search_hl_pos( next_search_hl_pos(
match_T *shl, /* points to a match */ match_T *shl, /* points to a match */
@@ -7781,55 +7785,52 @@ next_search_hl_pos(
colnr_T mincol) /* minimal column for a match */ colnr_T mincol) /* minimal column for a match */
{ {
int i; int i;
int bot = -1; int found = -1;
shl->lnum = 0;
for (i = posmatch->cur; i < MAXPOSMATCH; i++) for (i = posmatch->cur; i < MAXPOSMATCH; i++)
{ {
llpos_T *pos = &posmatch->pos[i]; llpos_T *pos = &posmatch->pos[i];
if (pos->lnum == 0) if (pos->lnum == 0)
break; break;
if (pos->col + pos->len - 1 <= mincol) if (pos->len == 0 && pos->col < mincol)
continue; continue;
if (pos->lnum == lnum) if (pos->lnum == lnum)
{ {
if (shl->lnum == lnum) if (found >= 0)
{ {
/* partially sort positions by column numbers /* if this match comes before the one at "found" then swap
* on the same line */ * them */
if (pos->col < posmatch->pos[bot].col) if (pos->col < posmatch->pos[found].col)
{ {
llpos_T tmp = *pos; llpos_T tmp = *pos;
*pos = posmatch->pos[bot]; *pos = posmatch->pos[found];
posmatch->pos[bot] = tmp; posmatch->pos[found] = tmp;
} }
} }
else else
{ found = i;
bot = i;
shl->lnum = lnum;
}
} }
} }
posmatch->cur = 0; posmatch->cur = 0;
if (shl->lnum == lnum && bot >= 0) if (found >= 0)
{ {
colnr_T start = posmatch->pos[bot].col == 0 colnr_T start = posmatch->pos[found].col == 0
? 0 : posmatch->pos[bot].col - 1; ? 0 : posmatch->pos[found].col - 1;
colnr_T end = posmatch->pos[bot].col == 0 colnr_T end = posmatch->pos[found].col == 0
? MAXCOL : start + posmatch->pos[bot].len; ? MAXCOL : start + posmatch->pos[found].len;
shl->lnum = lnum;
shl->rm.startpos[0].lnum = 0; shl->rm.startpos[0].lnum = 0;
shl->rm.startpos[0].col = start; shl->rm.startpos[0].col = start;
shl->rm.endpos[0].lnum = 0; shl->rm.endpos[0].lnum = 0;
shl->rm.endpos[0].col = end; shl->rm.endpos[0].col = end;
shl->is_addpos = TRUE; shl->is_addpos = TRUE;
posmatch->cur = bot + 1; posmatch->cur = found + 1;
return TRUE; return 1;
} }
return FALSE; return 0;
} }
#endif #endif

View File

@@ -191,7 +191,15 @@ func Test_matchaddpos()
call assert_equal(screenattr(2,2), screenattr(1,7)) call assert_equal(screenattr(2,2), screenattr(1,7))
call assert_notequal(screenattr(2,2), screenattr(1,8)) call assert_notequal(screenattr(2,2), screenattr(1,8))
call clearmatches()
call matchaddpos('Error', [[1], [2,2]])
redraw!
call assert_equal(screenattr(2,2), screenattr(1,1))
call assert_equal(screenattr(2,2), screenattr(1,10))
call assert_notequal(screenattr(2,2), screenattr(1,11))
nohl nohl
call clearmatches()
syntax off syntax off
set hlsearch& set hlsearch&
endfunc endfunc

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
40,
/**/ /**/
39, 39,
/**/ /**/