diff options
Diffstat (limited to 'src/nvim/screen.c')
-rw-r--r-- | src/nvim/screen.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c index ac8d14efb1..50517d2829 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -5698,6 +5698,8 @@ next_search_hl ( } } +/// If there is a match fill "shl" and return one. +/// Return zero otherwise. static int next_search_hl_pos( match_T *shl, // points to a match @@ -5707,7 +5709,7 @@ next_search_hl_pos( ) { int i; - int bot = -1; + int found = -1; shl->lnum = 0; for (i = posmatch->cur; i < MAXPOSMATCH; i++) { @@ -5716,41 +5718,41 @@ next_search_hl_pos( if (pos->lnum == 0) { break; } - if (pos->col + pos->len - 1 <= mincol) { + if (pos->len == 0 && pos->col < mincol) { continue; } if (pos->lnum == lnum) { - if (bot != -1) { - // partially sort positions by column numbers - // on the same line - if (pos->col < posmatch->pos[bot].col) { + if (found >= 0) { + // if this match comes before the one at "found" then swap + // them + if (pos->col < posmatch->pos[found].col) { llpos_T tmp = *pos; - *pos = posmatch->pos[bot]; - posmatch->pos[bot] = tmp; + *pos = posmatch->pos[found]; + posmatch->pos[found] = tmp; } } else { - bot = i; - shl->lnum = lnum; + found = i; } } } posmatch->cur = 0; - if (bot != -1) { - colnr_T start = posmatch->pos[bot].col == 0 - ? 0: posmatch->pos[bot].col - 1; - colnr_T end = posmatch->pos[bot].col == 0 - ? MAXCOL : start + posmatch->pos[bot].len; + if (found >= 0) { + colnr_T start = posmatch->pos[found].col == 0 + ? 0: posmatch->pos[found].col - 1; + colnr_T end = posmatch->pos[found].col == 0 + ? MAXCOL : start + posmatch->pos[found].len; + shl->lnum = lnum; shl->rm.startpos[0].lnum = 0; shl->rm.startpos[0].col = start; shl->rm.endpos[0].lnum = 0; shl->rm.endpos[0].col = end; shl->is_addpos = true; - posmatch->cur = bot + 1; - return true; + posmatch->cur = found + 1; + return 1; } - return false; + return 0; } static void screen_start_highlight(int attr) |