Patch 8.2.4805
Problem: CurSearch used for all matches in current line.
Solution: Don't use the non-zero line count. (closes #10247)
Files: src/match.c, src/testdir/test_search.vim,
src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump,
src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump,
src/testdir/dumps/Test_hlsearch_cursearch_single_line_2a.dump,
src/testdir/dumps/Test_hlsearch_cursearch_single_line_2b.dump
*** ../vim-8.2.4804/src/match.c 2022-04-16 12:03:34.176519007 +0100
--- src/match.c 2022-04-22 19:53:04.597242869 +0100
***************
*** 618,623 ****
--- 618,643 ----
}
/*
+ * Update "shl->has_cursor" based on the match in "shl" and the cursor
+ * position.
+ */
+ static void
+ check_cur_search_hl(win_T *wp, match_T *shl)
+ {
+ long linecount = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
+
+ if (wp->w_cursor.lnum >= shl->lnum
+ && wp->w_cursor.lnum <= shl->lnum + shl->rm.endpos[0].lnum
+ && (wp->w_cursor.lnum > shl->lnum
+ || wp->w_cursor.col >= shl->rm.startpos[0].col)
+ && (wp->w_cursor.lnum < shl->lnum + linecount
+ || wp->w_cursor.col < shl->rm.endpos[0].col))
+ shl->has_cursor = TRUE;
+ else
+ shl->has_cursor = FALSE;
+ }
+
+ /*
* Prepare for 'hlsearch' and match highlighting in one window line.
* Return TRUE if there is such highlighting and set "search_attr" to the
* current highlight attribute.
***************
*** 677,696 ****
shl->endcol = shl->rm.endpos[0].col;
else
shl->endcol = MAXCOL;
! if (shl->rm.endpos[0].lnum != shl->rm.startpos[0].lnum)
! shl->lines = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
! else
shl->lines = 1;
// check if the cursor is in the match before changing the columns
! if (wp->w_cursor.lnum >= shl->lnum
! && wp->w_cursor.lnum
! <= shl->lnum + shl->rm.endpos[0].lnum
! && (wp->w_cursor.lnum > shl->lnum
! || wp->w_cursor.col >= shl->rm.startpos[0].col)
! && (wp->w_cursor.lnum < shl->lnum + shl->lines
! || wp->w_cursor.col < shl->rm.endpos[0].col))
! shl->has_cursor = TRUE;
// Highlight one character for an empty match.
if (shl->startcol == shl->endcol)
--- 697,709 ----
shl->endcol = shl->rm.endpos[0].col;
else
shl->endcol = MAXCOL;
! shl->lines = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
! if (shl->lines == 0)
shl->lines = 1;
// check if the cursor is in the match before changing the columns
! if (shl == search_hl)
! check_cur_search_hl(wp, shl);
// Highlight one character for an empty match.
if (shl->startcol == shl->endcol)
***************
*** 811,816 ****
--- 824,833 ----
else
shl->endcol = MAXCOL;
+ // check if the cursor is in the match
+ if (shl == search_hl)
+ check_cur_search_hl(wp, shl);
+
if (shl->startcol == shl->endcol)
{
// highlight empty match, try again after
*** ../vim-8.2.4804/src/testdir/test_search.vim 2022-04-16 12:03:34.176519007 +0100
--- src/testdir/test_search.vim 2022-04-22 20:04:06.909060627 +0100
***************
*** 1043,1049 ****
let lines =<< trim END
set hlsearch scrolloff=0
! call setline(1, ['one', 'foo', 'bar', 'baz', 'foo', 'bar'])
hi Search ctermbg=yellow
hi CurSearch ctermbg=blue
END
--- 1043,1049 ----
let lines =<< trim END
set hlsearch scrolloff=0
! call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar'])
hi Search ctermbg=yellow
hi CurSearch ctermbg=blue
END
***************
*** 1056,1062 ****
call term_sendkeys(buf, "n")
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {})
! call term_sendkeys(buf, "?\<CR>")
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
--- 1056,1069 ----
call term_sendkeys(buf, "n")
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {})
! call term_sendkeys(buf, "n")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2a', {})
!
! call term_sendkeys(buf, "n")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2b', {})
!
! call term_sendkeys(buf, ":call setline(5, 'foo')\<CR>")
! call term_sendkeys(buf, "0?\<CR>")
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
*** ../vim-8.2.4804/src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump 2022-04-09 21:02:58.510251761 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump 2022-04-22 19:58:51.753170790 +0100
***************
*** 2,8 ****
>f+0࿈ff13|o@1| +0&#ffffff0@56
|b|a|r| @56
|b|a|z| @56
! |f+0&#ffff4012|o@1| +0&#ffffff0@56
|b|a|r| @56
|~+0#4040ff13&| @58
|~| @58
--- 2,8 ----
>f+0࿈ff13|o@1| +0&#ffffff0@56
|b|a|r| @56
|b|a|z| @56
! |f+0&#ffff4012|o@1| +0&#ffffff0|t|h|e| |f+0&#ffff4012|o@1| +0&#ffffff0|a|n|d| |f+0&#ffff4012|o@1| +0&#ffffff0@40
|b|a|r| @56
|~+0#4040ff13&| @58
|~| @58
*** ../vim-8.2.4804/src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump 2022-04-09 21:02:58.510251761 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump 2022-04-22 19:58:52.813170474 +0100
***************
*** 2,8 ****
|f+0&#ffff4012|o@1| +0&#ffffff0@56
|b|a|r| @56
|b|a|z| @56
! >f+0࿈ff13|o@1| +0&#ffffff0@56
|b|a|r| @56
|~+0#4040ff13&| @58
|~| @58
--- 2,8 ----
|f+0&#ffff4012|o@1| +0&#ffffff0@56
|b|a|r| @56
|b|a|z| @56
! >f+0࿈ff13|o@1| +0&#ffffff0|t|h|e| |f+0&#ffff4012|o@1| +0&#ffffff0|a|n|d| |f+0&#ffff4012|o@1| +0&#ffffff0@40
|b|a|r| @56
|~+0#4040ff13&| @58
|~| @58
*** ../vim-8.2.4804/src/testdir/dumps/Test_hlsearch_cursearch_single_line_2a.dump 2022-04-22 20:05:02.493038508 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_single_line_2a.dump 2022-04-22 20:00:37.045137373 +0100
***************
*** 0 ****
--- 1,9 ----
+ |o+0&#ffffff0|n|e| @56
+ |f+0&#ffff4012|o@1| +0&#ffffff0@56
+ |b|a|r| @56
+ |b|a|z| @56
+ |f+0&#ffff4012|o@1| +0&#ffffff0|t|h|e| >f+0࿈ff13|o@1| +0&#ffffff0|a|n|d| |f+0&#ffff4012|o@1| +0&#ffffff0@40
+ |b|a|r| @56
+ |~+0#4040ff13&| @58
+ |~| @58
+ |/+0#0000000&|f|o@1| @37|5|,|9| @10|A|l@1|
*** ../vim-8.2.4804/src/testdir/dumps/Test_hlsearch_cursearch_single_line_2b.dump 2022-04-22 20:06:43.496996867 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_single_line_2b.dump 2022-04-22 20:00:38.101137019 +0100
***************
*** 0 ****
--- 1,9 ----
+ |o+0&#ffffff0|n|e| @56
+ |f+0&#ffff4012|o@1| +0&#ffffff0@56
+ |b|a|r| @56
+ |b|a|z| @56
+ |f+0&#ffff4012|o@1| +0&#ffffff0|t|h|e| |f+0&#ffff4012|o@1| +0&#ffffff0|a|n|d| >f+0࿈ff13|o@1| +0&#ffffff0@40
+ |b|a|r| @56
+ |~+0#4040ff13&| @58
+ |~| @58
+ |/+0#0000000&|f|o@1| @37|5|,|1|7| @9|A|l@1|
*** ../vim-8.2.4804/src/version.c 2022-04-21 23:29:58.948561831 +0100
--- src/version.c 2022-04-22 20:05:19.609031587 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4805,
/**/
--
Know this story about a nerd who fell into a river and drowned,
despite his cries of "F1! F1!"?
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///