summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-04-16 12:04:37 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-16 12:04:37 +0100
commit693ccd11606b59eb0f81c6c1948679e61ada4022 (patch)
treeae4dd7c16456840fb3dca1b590340cf61d7fd930 /src
parent3b470ae88f034d3741832ab1cc51a5bb8edaf4c6 (diff)
downloadvim-git-693ccd11606b59eb0f81c6c1948679e61ada4022.tar.gz
patch 8.2.4759: CurSearch highlight does not work for multi-line matchv8.2.4759
Problem: CurSearch highlight does not work for multi-line match. Solution: Check cursor position before adjusting columns. (closes #10133)
Diffstat (limited to 'src')
-rw-r--r--src/match.c21
-rw-r--r--src/structs.h4
-rw-r--r--src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_1.dump (renamed from src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump)0
-rw-r--r--src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump9
-rw-r--r--src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump9
-rw-r--r--src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump9
-rw-r--r--src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump9
-rw-r--r--src/testdir/test_search.vim12
-rw-r--r--src/version.c2
9 files changed, 66 insertions, 9 deletions
diff --git a/src/match.c b/src/match.c
index d74d8d73f..9edba8d99 100644
--- a/src/match.c
+++ b/src/match.c
@@ -396,6 +396,7 @@ next_search_hl_pos(
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,6 +656,7 @@ prepare_search_hl_line(
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,6 +681,17 @@ prepare_search_hl_line(
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,14 +788,8 @@ update_search_hl(
# 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)
- {
+ if (shl == search_hl && shl->has_cursor)
shl->attr_cur = HL_ATTR(HLF_LC);
- }
}
else if (col == shl->endcol)
diff --git a/src/structs.h b/src/structs.h
index 176a86c1a..b77fa3488 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -3337,8 +3337,10 @@ typedef struct
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
+ 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
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_1.dump
index 950ffef61..950ffef61 100644
--- a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump
+++ b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_1.dump
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump
new file mode 100644
index 000000000..7b091cf33
--- /dev/null
+++ b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_2.dump
@@ -0,0 +1,9 @@
+|-+0&#ffffff0@2| @56
+|a|b|c|d>e+0&#4040ff13|f|g| | +0&#ffffff0@51
+|h+0&#4040ff13|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|
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump
new file mode 100644
index 000000000..ef03675d3
--- /dev/null
+++ b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_3.dump
@@ -0,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|
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump
new file mode 100644
index 000000000..2235295d8
--- /dev/null
+++ b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_4.dump
@@ -0,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|
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump
new file mode 100644
index 000000000..2294566ff
--- /dev/null
+++ b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line_5.dump
@@ -0,0 +1,9 @@
+|-+0&#ffffff0@2| @56
+|a|b|c|d|e+0&#4040ff13|f|g| | +0&#ffffff0@51
+|h+0&#4040ff13|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|
diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim
index 4ed249d39..97ddfdbc6 100644
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -1060,7 +1060,17 @@ func Test_hlsearch_cursearch()
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 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')
diff --git a/src/version.c b/src/version.c
index 2a3e8d603..4c28b3789 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4759,
+/**/
4758,
/**/
4757,