aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-06-19 08:24:29 +0800
committerGitHub <noreply@github.com>2024-06-19 08:24:29 +0800
commitb381b2d529741ddd4f3664959640917a10cd91b5 (patch)
tree4c606a997f28a74b531ab2888e2f59eac5329d70 /src
parenta2d510e1015d57f28ab20c5d2897527cae15b9c4 (diff)
parenta2a3e8412e6d4e9a952c57a5298016cae8bf5229 (diff)
downloadrneovim-b381b2d529741ddd4f3664959640917a10cd91b5.tar.gz
rneovim-b381b2d529741ddd4f3664959640917a10cd91b5.tar.bz2
rneovim-b381b2d529741ddd4f3664959640917a10cd91b5.zip
Merge pull request #29404 from zeertzjq/vim-8.2.4724
vim-patch:8.2.{4724,5047}: make CurSearch behavior match Vim
Diffstat (limited to 'src')
-rw-r--r--src/nvim/change.c4
-rw-r--r--src/nvim/drawscreen.c13
-rw-r--r--src/nvim/drawscreen.h6
-rw-r--r--src/nvim/match.c3
-rw-r--r--src/nvim/move.c7
-rw-r--r--src/nvim/normal.c12
-rw-r--r--src/nvim/search.c6
7 files changed, 39 insertions, 12 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 6c979df1fe..428a9187c8 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -392,6 +392,10 @@ static void changed_common(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnum
}
}
}
+
+ if (wp == curwin && xtra != 0 && search_hl_has_cursor_lnum >= lnum) {
+ search_hl_has_cursor_lnum += xtra;
+ }
}
// Call update_screen() later, which checks out what needs to be redrawn,
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 88e1f302da..770f8da6cf 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -1593,6 +1593,18 @@ static void win_update(win_T *wp)
}
}
}
+
+ if (search_hl_has_cursor_lnum > 0) {
+ // CurSearch was used last time, need to redraw the line with it to
+ // avoid having two matches highlighted with CurSearch.
+ if (mod_top == 0 || mod_top > search_hl_has_cursor_lnum) {
+ mod_top = search_hl_has_cursor_lnum;
+ }
+ if (mod_bot == 0 || mod_bot < search_hl_has_cursor_lnum + 1) {
+ mod_bot = search_hl_has_cursor_lnum + 1;
+ }
+ }
+
if (mod_top != 0 && hasAnyFolding(wp)) {
// A change in a line can cause lines above it to become folded or
// unfolded. Find the top most buffer line that may be affected.
@@ -1651,6 +1663,7 @@ static void win_update(win_T *wp)
wp->w_redraw_top = 0; // reset for next time
wp->w_redraw_bot = 0;
+ search_hl_has_cursor_lnum = 0;
// When only displaying the lines at the top, set top_end. Used when
// window has scrolled down for msg_scrolled.
diff --git a/src/nvim/drawscreen.h b/src/nvim/drawscreen.h
index f804345bca..36ba8099fd 100644
--- a/src/nvim/drawscreen.h
+++ b/src/nvim/drawscreen.h
@@ -25,7 +25,11 @@ EXTERN bool updating_screen INIT( = false);
/// must_redraw to be set.
EXTERN bool redraw_not_allowed INIT( = false);
-EXTERN match_T screen_search_hl INIT( = { 0 }); ///< used for 'hlsearch' highlight matching
+/// used for 'hlsearch' highlight matching
+EXTERN match_T screen_search_hl INIT( = { 0 });
+
+/// last lnum where CurSearch was displayed
+EXTERN linenr_T search_hl_has_cursor_lnum INIT( = 0);
#define W_ENDCOL(wp) ((wp)->w_wincol + (wp)->w_width)
#define W_ENDROW(wp) ((wp)->w_winrow + (wp)->w_height)
diff --git a/src/nvim/match.c b/src/nvim/match.c
index 6ae4e41147..86cab5221d 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -706,6 +706,9 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T
// group.
if (shl == search_hl && shl->has_cursor) {
shl->attr_cur = win_hl_attr(wp, HLF_LC);
+ if (shl->attr_cur != shl->attr) {
+ search_hl_has_cursor_lnum = lnum;
+ }
} else {
shl->attr_cur = shl->attr;
}
diff --git a/src/nvim/move.c b/src/nvim/move.c
index a2bb1b4685..e942f58711 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -153,7 +153,6 @@ static void redraw_for_cursorline(win_T *wp)
/// Redraw when w_virtcol changes and
/// - 'cursorcolumn' is set, or
/// - 'cursorlineopt' contains "screenline", or
-/// - "CurSearch" highlight is in use, or
/// - 'concealcursor' is active, or
/// - Visual mode is active.
static void redraw_for_cursorcolumn(win_T *wp)
@@ -173,10 +172,8 @@ static void redraw_for_cursorcolumn(win_T *wp)
return;
}
- if (wp->w_p_cuc
- || (win_hl_attr(wp, HLF_LC) != win_hl_attr(wp, HLF_L) && using_hlsearch())) {
- // When 'cursorcolumn' is set or "CurSearch" is in use
- // need to redraw with UPD_SOME_VALID.
+ if (wp->w_p_cuc) {
+ // When 'cursorcolumn' is set need to redraw with UPD_SOME_VALID.
redraw_later(wp, UPD_SOME_VALID);
} else if (wp->w_p_cul && (wp->w_p_culopt_flags & CULOPT_SCRLINE)) {
// When 'cursorlineopt' contains "screenline" need to redraw with UPD_VALID.
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 3343803bb1..cbd068401a 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -3973,6 +3973,12 @@ static void nv_next(cmdarg_T *cap)
normal_search(cap, 0, NULL, 0, SEARCH_MARK | cap->arg, NULL);
cap->count1 -= 1;
}
+
+ // Redraw the window to refresh the highlighted matches.
+ if (i > 0 && p_hls && !no_hlsearch
+ && win_hl_attr(curwin, HLF_LC) != win_hl_attr(curwin, HLF_L)) {
+ redraw_later(curwin, UPD_SOME_VALID);
+ }
}
/// Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
@@ -3984,6 +3990,7 @@ static void nv_next(cmdarg_T *cap)
static int normal_search(cmdarg_T *cap, int dir, char *pat, size_t patlen, int opt, int *wrapped)
{
searchit_arg_T sia;
+ pos_T const prev_cursor = curwin->w_cursor;
cap->oap->motion_type = kMTCharWise;
cap->oap->inclusive = false;
@@ -4007,6 +4014,11 @@ static int normal_search(cmdarg_T *cap, int dir, char *pat, size_t patlen, int o
foldOpenCursor();
}
}
+ // Redraw the window to refresh the highlighted matches.
+ if (!equalpos(curwin->w_cursor, prev_cursor) && p_hls && !no_hlsearch
+ && win_hl_attr(curwin, HLF_LC) != win_hl_attr(curwin, HLF_L)) {
+ redraw_later(curwin, UPD_SOME_VALID);
+ }
// "/$" will put the cursor after the end of the line, may need to
// correct that here
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 994a0794b0..4d817b2418 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -4322,9 +4322,3 @@ bool search_was_last_used(void)
{
return last_idx == 0;
}
-
-/// @return true if 'hlsearch' highlight is currently in use.
-bool using_hlsearch(void)
-{
- return spats[last_idx].pat != NULL && p_hls && !no_hlsearch;
-}