Patch 8.2.4759
Problem: CurSearch highlight does not work for multi-line match.
Solution: Check cursor position before adjusting columns. (closes #10133)
Files: src/structs.h, src/match.c, src/testdir/test_search.vim,
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump,
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_1.dump,
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump,
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump,
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump,
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump
*** ../vim-8.2.4758/src/structs.h 2022-04-14 15:39:39.281754582 +0100
--- src/structs.h 2022-04-16 11:17:03.939337659 +0100
***************
*** 3337,3344 ****
linenr_T first_lnum; // first lnum to search for multi-line pat
colnr_T startcol; // in win_line() points to char where HL starts
colnr_T endcol; // in win_line() points to char where HL ends
! int is_addpos; // position specified directly by
// matchaddpos(). TRUE/FALSE
#ifdef FEAT_RELTIME
proftime_T tm; // for a time limit
#endif
--- 3337,3346 ----
linenr_T first_lnum; // first lnum to search for multi-line pat
colnr_T startcol; // in win_line() points to char where HL starts
colnr_T endcol; // in win_line() points to char where HL ends
! char is_addpos; // position specified directly by
// matchaddpos(). TRUE/FALSE
+ char has_cursor; // TRUE if the cursor is inside the match, used for
+ // CurSearch
#ifdef FEAT_RELTIME
proftime_T tm; // for a time limit
#endif
*** ../vim-8.2.4758/src/match.c 2022-04-09 21:02:58.506251763 +0100
--- src/match.c 2022-04-16 11:44:03.372852487 +0100
***************
*** 396,401 ****
--- 396,402 ----
shl->rm.endpos[0].lnum = 0;
shl->rm.endpos[0].col = end;
shl->is_addpos = TRUE;
+ shl->has_cursor = FALSE;
posmatch->cur = found + 1;
return 1;
}
***************
*** 655,660 ****
--- 656,662 ----
shl->lines = 0;
shl->attr_cur = 0;
shl->is_addpos = FALSE;
+ shl->has_cursor = FALSE;
if (cur != NULL)
cur->pos.cur = 0;
next_search_hl(wp, search_hl, shl, lnum, mincol,
***************
*** 679,684 ****
--- 681,697 ----
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)
{
***************
*** 775,788 ****
# endif
// Highlight the match were the cursor is using the CurSearch
// group.
! if (shl == search_hl
! && wp->w_cursor.lnum >= shl->lnum
! && wp->w_cursor.lnum < shl->lnum + shl->lines
! && wp->w_cursor.col >= shl->startcol
! && wp->w_cursor.col < shl->endcol)
! {
shl->attr_cur = HL_ATTR(HLF_LC);
- }
}
else if (col == shl->endcol)
--- 788,795 ----
# endif
// Highlight the match were the cursor is using the CurSearch
// group.
! if (shl == search_hl && shl->has_cursor)
shl->attr_cur = HL_ATTR(HLF_LC);
}
else if (col == shl->endcol)
*** ../vim-8.2.4758/src/testdir/test_search.vim 2022-04-09 21:02:58.510251761 +0100
--- src/testdir/test_search.vim 2022-04-16 11:56:53.237704192 +0100
***************
*** 1060,1066 ****
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line', {})
call StopVimInTerminal(buf)
call delete('Xhlsearch_cursearch')
--- 1060,1076 ----
call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_1', {})
!
! call term_sendkeys(buf, ":call setline(1, ['---', 'abcdefg', 'hijkl', '---', 'abcdefg', 'hijkl'])\<CR>")
! call term_sendkeys(buf, "gg/efg\\nhij\<CR>")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_2', {})
! call term_sendkeys(buf, "h\<C-L>")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_3', {})
! call term_sendkeys(buf, "j\<C-L>")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_4', {})
! call term_sendkeys(buf, "h\<C-L>")
! call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_5', {})
call StopVimInTerminal(buf)
call delete('Xhlsearch_cursearch')
*** ../vim-8.2.4758/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump 2022-04-09 21:02:58.510251761 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump 1970-01-01 00:00:00.000000000 +0000
***************
*** 1,9 ****
- |o+0&#ffffff0|n|e| @56
- >f+0࿈ff13|o@1| | +0&#ffffff0@55
- |b+0࿈ff13|a|r| +0&#ffffff0@56
- |b|a|z| @56
- |f+0&#ffff4012|o@1| | +0&#ffffff0@55
- |b+0&#ffff4012|a|r| +0&#ffffff0@56
- |~+0#4040ff13&| @58
- |~| @58
- |/+0#0000000&|f|o@1|\|n|b|a|r| @32|2|,|1| @10|A|l@1|
--- 0 ----
*** ../vim-8.2.4758/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_1.dump 2022-04-16 12:03:15.972564643 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_1.dump 2022-04-09 20:57:03.766378022 +0100
***************
*** 0 ****
--- 1,9 ----
+ |o+0&#ffffff0|n|e| @56
+ >f+0࿈ff13|o@1| | +0&#ffffff0@55
+ |b+0࿈ff13|a|r| +0&#ffffff0@56
+ |b|a|z| @56
+ |f+0&#ffff4012|o@1| | +0&#ffffff0@55
+ |b+0&#ffff4012|a|r| +0&#ffffff0@56
+ |~+0#4040ff13&| @58
+ |~| @58
+ |/+0#0000000&|f|o@1|\|n|b|a|r| @32|2|,|1| @10|A|l@1|
*** ../vim-8.2.4758/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump 2022-04-16 12:03:15.976564632 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump 2022-04-16 11:55:10.198092852 +0100
***************
*** 0 ****
--- 1,9 ----
+ |-+0&#ffffff0@2| @56
+ |a|b|c|d>e+0࿈ff13|f|g| | +0&#ffffff0@51
+ |h+0࿈ff13|i|j|k+0&#ffffff0|l| @54
+ |-@2| @56
+ |a|b|c|d|e+0&#ffff4012|f|g| | +0&#ffffff0@51
+ |h+0&#ffff4012|i|j|k+0&#ffffff0|l| @54
+ |~+0#4040ff13&| @58
+ |~| @58
+ |/+0#0000000&|e|f|g|\|n|h|i|j| @32|2|,|5| @10|A|l@1|
*** ../vim-8.2.4758/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump 2022-04-16 12:03:15.980564623 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump 2022-04-16 11:55:11.258088616 +0100
***************
*** 0 ****
--- 1,9 ----
+ |-+0&#ffffff0@2| @56
+ |a|b|c>d|e+0&#ffff4012|f|g| | +0&#ffffff0@51
+ |h+0&#ffff4012|i|j|k+0&#ffffff0|l| @54
+ |-@2| @56
+ |a|b|c|d|e+0&#ffff4012|f|g| | +0&#ffffff0@51
+ |h+0&#ffff4012|i|j|k+0&#ffffff0|l| @54
+ |~+0#4040ff13&| @58
+ |~| @58
+ | +0#0000000&@41|2|,|4| @10|A|l@1|
*** ../vim-8.2.4758/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump 2022-04-16 12:03:15.984564613 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump 2022-04-16 11:55:12.322084371 +0100
***************
*** 0 ****
--- 1,9 ----
+ |-+0&#ffffff0@2| @56
+ |a|b|c|d|e+0&#ffff4012|f|g| | +0&#ffffff0@51
+ |h+0&#ffff4012|i|j>k+0&#ffffff0|l| @54
+ |-@2| @56
+ |a|b|c|d|e+0&#ffff4012|f|g| | +0&#ffffff0@51
+ |h+0&#ffff4012|i|j|k+0&#ffffff0|l| @54
+ |~+0#4040ff13&| @58
+ |~| @58
+ | +0#0000000&@41|3|,|4| @10|A|l@1|
*** ../vim-8.2.4758/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump 2022-04-16 12:03:15.988564601 +0100
--- src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump 2022-04-16 11:56:56.401692949 +0100
***************
*** 0 ****
--- 1,9 ----
+ |-+0&#ffffff0@2| @56
+ |a|b|c|d|e+0࿈ff13|f|g| | +0&#ffffff0@51
+ |h+0࿈ff13|i>j|k+0&#ffffff0|l| @54
+ |-@2| @56
+ |a|b|c|d|e+0&#ffff4012|f|g| | +0&#ffffff0@51
+ |h+0&#ffff4012|i|j|k+0&#ffffff0|l| @54
+ |~+0#4040ff13&| @58
+ |~| @58
+ | +0#0000000&@41|3|,|3| @10|A|l@1|
*** ../vim-8.2.4758/src/version.c 2022-04-16 10:40:59.085370585 +0100
--- src/version.c 2022-04-16 11:15:52.731572336 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4759,
/**/
--
A consultant is a person who takes your money and annoys your employees while
tirelessly searching for the best way to extend the consulting contract.
(Scott Adams - The Dilbert principle)
/// 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 ///