aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-06-19 07:32:53 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-06-19 08:02:02 +0800
commit14aba679670a6485596c60fa5eb1df92ecae8a1b (patch)
tree5ab2fbbf939d38ee2d6b75e1ff0263d60f129e5d
parenta2d510e1015d57f28ab20c5d2897527cae15b9c4 (diff)
downloadrneovim-14aba679670a6485596c60fa5eb1df92ecae8a1b.tar.gz
rneovim-14aba679670a6485596c60fa5eb1df92ecae8a1b.tar.bz2
rneovim-14aba679670a6485596c60fa5eb1df92ecae8a1b.zip
vim-patch:8.2.4724: current instance of last search pattern not easily spotted
Problem: Current instance of last search pattern not easily spotted. Solution: Add CurSearch highlighting. (closes vim/vim#10133) https://github.com/vim/vim/commit/a43993897aa372159f682df37562f159994dc85c Some code is superseded by later patches that are already ported. Co-authored-by: LemonBoy <thatlemon@gmail.com>
-rw-r--r--runtime/doc/news.txt2
-rw-r--r--runtime/doc/syntax.txt5
-rw-r--r--runtime/doc/vim_diff.txt2
-rw-r--r--src/nvim/move.c7
-rw-r--r--src/nvim/normal.c12
-rw-r--r--src/nvim/search.c6
6 files changed, 19 insertions, 15 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 4f9f0248df..840f860e3f 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -47,6 +47,8 @@ EDITOR
• The order in which signs are placed was changed. Higher priority signs will
now appear left of lower priority signs.
+• |hl-CurSearch| now behaves the same as Vim and no longer updates on every
+ cursor movement.
EVENTS
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index e73d5d442f..afc230e112 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -4969,8 +4969,9 @@ ColorColumn Used for the columns set with 'colorcolumn'.
Conceal Placeholder characters substituted for concealed
text (see 'conceallevel').
*hl-CurSearch*
-CurSearch Used for highlighting a search pattern under the cursor
- (see 'hlsearch').
+CurSearch Current match for the last search pattern (see 'hlsearch').
+ Note: This is correct after a search, but may get outdated if
+ changes are made or the screen is redrawn.
*hl-Cursor* *hl-lCursor*
Cursor Character under the cursor.
lCursor Character under the cursor when |language-mapping|
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index a6f08402f6..a51ffcf004 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -539,8 +539,6 @@ Functions:
Highlight groups:
- |hl-ColorColumn|, |hl-CursorColumn| are lower priority than most other
groups
-- |hl-CurSearch| highlights match under cursor instead of last match found
- using |n| or |N|
- |hl-CursorLine| is low-priority unless foreground color is set
- |hl-VertSplit| superseded by |hl-WinSeparator|
- Highlight groups names are allowed to contain `@` characters.
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;
-}