Skip to content

Commit 41f0895

Browse files
committed
patch 8.2.2542: highlight of char beyond line end is not correct
Problem: Highlight of char beyond line end is not correct. (Chuan Wei Foo) Solution: Fix counting NUL as one cell. Draw one more character if the EOL is part of the match. (closes #7883)
1 parent 6bfc475 commit 41f0895

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

src/match.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,15 @@ update_search_hl(
792792
// highlight empty match, try again after
793793
// it
794794
if (has_mbyte)
795-
shl->endcol += (*mb_ptr2len)(*line + shl->endcol);
795+
{
796+
char_u *p = *line + shl->endcol;
797+
798+
if (*p == NUL)
799+
// consistent with non-mbyte
800+
++shl->endcol;
801+
else
802+
shl->endcol += (*mb_ptr2len)(p);
803+
}
796804
else
797805
++shl->endcol;
798806
}
@@ -842,18 +850,31 @@ get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol)
842850
int prevcol_hl_flag = FALSE;
843851
matchitem_T *cur; // points to the match list
844852

853+
#if defined(FEAT_PROP_POPUP)
854+
// don't do this in a popup window
855+
if (popup_is_popup(wp))
856+
return FALSE;
857+
#endif
858+
845859
// we're not really at that column when skipping some text
846860
if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
847861
++prevcol;
848862

849-
if (!search_hl->is_addpos && prevcol == (long)search_hl->startcol)
863+
// Highlight a character after the end of the line if the match started
864+
// at the end of the line or when the match continues in the next line
865+
// (match includes the line break).
866+
if (!search_hl->is_addpos && (prevcol == (long)search_hl->startcol
867+
|| (prevcol > (long)search_hl->startcol
868+
&& search_hl->endcol == MAXCOL)))
850869
prevcol_hl_flag = TRUE;
851870
else
852871
{
853872
cur = wp->w_match_head;
854873
while (cur != NULL)
855874
{
856-
if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol)
875+
if (!cur->hl.is_addpos && (prevcol == (long)cur->hl.startcol
876+
|| (prevcol > (long)cur->hl.startcol
877+
&& cur->hl.endcol == MAXCOL)))
857878
{
858879
prevcol_hl_flag = TRUE;
859880
break;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|x+0&#ffff4012@2| | +0&#ffffff0@45
2+
>x+8&#ffff4012@2| | +8&#ffffff0@45
3+
|x+0&#ffff4012@2| | +0&#ffffff0@45
4+
|~+0#4040ff13&| @48
5+
|~| @48
6+
| +0#0000000&@31|2|,|1| @10|A|l@1|
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|x+0&#ffff4012@2| | +0&#ffffff0@45
2+
|x+0&#ffff4012@2| | +0&#ffffff0@45
3+
>x+8&#ffff4012@2| | +8&#ffffff0@45
4+
|~+0#4040ff13&| @48
5+
|~| @48
6+
|/+0#0000000&|\|_|.|*| @26|3|,|1| @10|A|l@1|

src/testdir/test_search.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,26 @@ func Test_incsearch_search_dump()
944944
call delete('Xis_search_script')
945945
endfunc
946946

947+
func Test_hlsearch_dump()
948+
CheckOption hlsearch
949+
CheckScreendump
950+
951+
call writefile([
952+
\ 'set hlsearch cursorline',
953+
\ 'call setline(1, ["xxx", "xxx", "xxx"])',
954+
\ '/.*',
955+
\ '2',
956+
\ ], 'Xhlsearch_script')
957+
let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50})
958+
call VerifyScreenDump(buf, 'Test_hlsearch_1', {})
959+
960+
call term_sendkeys(buf, "/\\_.*\<CR>")
961+
call VerifyScreenDump(buf, 'Test_hlsearch_2', {})
962+
963+
call StopVimInTerminal(buf)
964+
call delete('Xhlsearch_script')
965+
endfunc
966+
947967
func Test_incsearch_substitute()
948968
CheckOption incsearch
949969

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2542,
753755
/**/
754756
2541,
755757
/**/

0 commit comments

Comments
 (0)