aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/match.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-21 19:59:25 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-04-21 20:19:58 +0800
commit4b19f94c2800b6ab89db57919d35c9696f48cef7 (patch)
tree42fa6fe12cd07542605c96c595f75dbc65314975 /src/nvim/match.c
parente6dec30332f2538ae45d58e6bb674c8a28422fe9 (diff)
downloadrneovim-4b19f94c2800b6ab89db57919d35c9696f48cef7.tar.gz
rneovim-4b19f94c2800b6ab89db57919d35c9696f48cef7.tar.bz2
rneovim-4b19f94c2800b6ab89db57919d35c9696f48cef7.zip
vim-patch:8.2.4759: CurSearch highlight does not work for multi-line match
Problem: CurSearch highlight does not work for multi-line match. Solution: Check cursor position before adjusting columns. (closes vim/vim#10133) https://github.com/vim/vim/commit/693ccd11606b59eb0f81c6c1948679e61ada4022
Diffstat (limited to 'src/nvim/match.c')
-rw-r--r--src/nvim/match.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/nvim/match.c b/src/nvim/match.c
index 256e5812d4..f6d2fe13c4 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -373,6 +373,7 @@ static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *posmatch,
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;
}
@@ -585,6 +586,7 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char_u **l
shl->lines = 0;
shl->attr_cur = 0;
shl->is_addpos = false;
+ shl->has_cursor = false;
if (cur != NULL) {
cur->pos.cur = 0;
}
@@ -612,6 +614,17 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char_u **l
} 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) {
if ((*line)[shl->endcol] != NUL) {
@@ -676,12 +689,7 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match
}
// Highlight the match were the cursor is using the CurSearch
// group.
- if (shl == search_hl
- && (HL_ATTR(HLF_LC) || wp->w_hl_ids[HLF_LC])
- && wp->w_cursor.lnum == 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 && (HL_ATTR(HLF_LC) || wp->w_hl_ids[HLF_LC])) {
shl->attr_cur = win_hl_attr(wp, HLF_LC) ? win_hl_attr(wp, HLF_LC) : HL_ATTR(HLF_LC);
} else {
shl->attr_cur = shl->attr;