Skip to content

Commit e17bdff

Browse files
committed
patch 7.4.2269
Problem: Using 'hlsearch' highlighting instead of matchpos if there is no search match. Solution: Pass NULL as last item to next_search_hl() when searching for 'hlsearch' match. (Shane Harper, closes #1013)
1 parent 1195669 commit e17bdff

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/screen.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3546,7 +3546,8 @@ win_line(
35463546
v = (long)(ptr - line);
35473547
if (cur != NULL)
35483548
cur->pos.cur = 0;
3549-
next_search_hl(wp, shl, lnum, (colnr_T)v, cur);
3549+
next_search_hl(wp, shl, lnum, (colnr_T)v,
3550+
shl == &search_hl ? NULL : cur);
35503551

35513552
/* Need to get the line again, a multi-line regexp may have made it
35523553
* invalid. */
@@ -3980,7 +3981,8 @@ win_line(
39803981
#ifdef FEAT_CONCEAL
39813982
prev_syntax_id = 0;
39823983
#endif
3983-
next_search_hl(wp, shl, lnum, (colnr_T)v, cur);
3984+
next_search_hl(wp, shl, lnum, (colnr_T)v,
3985+
shl == &search_hl ? NULL : cur);
39843986
pos_inprogress = cur == NULL || cur->pos.cur == 0
39853987
? FALSE : TRUE;
39863988

@@ -7607,7 +7609,8 @@ prepare_search_hl(win_T *wp, linenr_T lnum)
76077609
while (shl->first_lnum < lnum && (shl->rm.regprog != NULL
76087610
|| (cur != NULL && pos_inprogress)))
76097611
{
7610-
next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, cur);
7612+
next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n,
7613+
shl == &search_hl ? NULL : cur);
76117614
pos_inprogress = cur == NULL || cur->pos.cur == 0
76127615
? FALSE : TRUE;
76137616
if (shl->lnum != 0)

src/testdir/test_match.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,31 @@ func Test_matchaddpos()
186186
set hlsearch&
187187
endfunc
188188

189+
func Test_matchaddpos_using_negative_priority()
190+
set hlsearch
191+
192+
call clearmatches()
193+
194+
call setline(1, 'x')
195+
let @/='x'
196+
redraw!
197+
let search_attr = screenattr(1,1)
198+
199+
let @/=''
200+
call matchaddpos('Error', [1], 10)
201+
redraw!
202+
let error_attr = screenattr(1,1)
203+
204+
call setline(2, '-1 match priority')
205+
call matchaddpos('Error', [2], -1)
206+
redraw!
207+
let negative_match_priority_attr = screenattr(2,1)
208+
209+
call assert_notequal(negative_match_priority_attr, search_attr, "Match with negative priority is incorrectly highlighted with Search highlight.")
210+
call assert_equal(negative_match_priority_attr, error_attr)
211+
212+
nohl
213+
set hlsearch&
214+
endfunc
215+
189216
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2269,
766768
/**/
767769
2268,
768770
/**/

0 commit comments

Comments
 (0)