changeset 29050:a2710736125a v8.2.5047

patch 8.2.5047: CurSearch highlight is often wrong Commit: https://github.com/vim/vim/commit/368137aa525982984beed73940af481ac53a62af Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 31 13:43:12 2022 +0100 patch 8.2.5047: CurSearch highlight is often wrong Problem: CurSearch highlight is often wrong. Solution: Remember the last highlighted position and redraw when needed.
author Bram Moolenaar <Bram@vim.org>
date Tue, 31 May 2022 14:45:03 +0200
parents 947c2f51b6f7
children 0b695d368511
files src/change.c src/drawscreen.c src/globals.h src/match.c src/testdir/dumps/Test_hlsearch_cursearch_changed_1.dump src/testdir/test_search.vim src/version.c
diffstat 7 files changed, 49 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/change.c
+++ b/src/change.c
@@ -663,6 +663,10 @@ changed_common(
 	    }
 #endif
 	}
+#ifdef FEAT_SEARCH_EXTRA
+	if (wp == curwin && xtra != 0 && search_hl_has_cursor_lnum >= lnum)
+	    search_hl_has_cursor_lnum += xtra;
+#endif
     }
 
     // Call update_screen() later, which checks out what needs to be redrawn,
--- a/src/drawscreen.c
+++ b/src/drawscreen.c
@@ -1618,6 +1618,19 @@ win_update(win_T *wp)
 	    }
 #endif
 	}
+
+#ifdef FEAT_SEARCH_EXTRA
+	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;
+	}
+#endif
+
 #ifdef FEAT_FOLDING
 	if (mod_top != 0 && hasAnyFolding(wp))
 	{
@@ -1684,6 +1697,10 @@ win_update(win_T *wp)
     }
     wp->w_redraw_top = 0;	// reset for next time
     wp->w_redraw_bot = 0;
+#ifdef FEAT_SEARCH_EXTRA
+    search_hl_has_cursor_lnum = 0;
+#endif
+
 
     // When only displaying the lines at the top, set top_end.  Used when
     // window has scrolled down for msg_scrolled.
--- a/src/globals.h
+++ b/src/globals.h
@@ -75,7 +75,14 @@ EXTERN int	screen_cur_row INIT(= 0);
 EXTERN int	screen_cur_col INIT(= 0);
 
 #ifdef FEAT_SEARCH_EXTRA
-EXTERN match_T	screen_search_hl; // used for 'hlsearch' highlight matching
+// used for 'hlsearch' highlight matching
+EXTERN match_T	screen_search_hl;
+
+// last lnum where CurSearch was displayed
+EXTERN linenr_T search_hl_has_cursor_lnum INIT(= 0);
+
+// don't use 'hlsearch' temporarily
+EXTERN int	no_hlsearch INIT(= FALSE);
 #endif
 
 #ifdef FEAT_FOLDING
@@ -1418,11 +1425,6 @@ EXTERN char_u	wim_flags[4];
 EXTERN int      stl_syntax INIT(= 0);
 #endif
 
-#ifdef FEAT_SEARCH_EXTRA
-// don't use 'hlsearch' temporarily
-EXTERN int	no_hlsearch INIT(= FALSE);
-#endif
-
 #if defined(FEAT_BEVAL) && !defined(NO_X11_INCLUDES)
 EXTERN BalloonEval	*balloonEval INIT(= NULL);
 EXTERN int		balloonEvalForTerm INIT(= FALSE);
--- a/src/match.c
+++ b/src/match.c
@@ -798,7 +798,11 @@ update_search_hl(
 		// 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);
+		    if (shl->attr_cur != shl->attr)
+			search_hl_has_cursor_lnum = lnum;
+		}
 
 	    }
 	    else if (col == shl->endcol)
new file mode 100644
--- /dev/null
+++ b/src/testdir/dumps/Test_hlsearch_cursearch_changed_1.dump
@@ -0,0 +1,9 @@
+|-+0&#ffffff0@2| @56
+|a+0&#ffff4012|b|c|d|e+0&#ffffff0|f|g| @52
+>a+0&#4040ff13|b|c|d|e+0&#ffffff0|f|g| @52
+|h|i|j|k|l| @54
+|-@2| @56
+|a+0&#ffff4012|b|c|d|e+0&#ffffff0|f|g| @52
+|h|i|j|k|l| @54
+|~+0#4040ff13&| @58
+| +0#0000000&@41|3|,|1| @10|A|l@1| 
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -1079,6 +1079,11 @@ func Test_hlsearch_cursearch()
   call term_sendkeys(buf, "h\<C-L>")
   call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_5', {})
 
+  " check clearing CurSearch when using it for another match
+  call term_sendkeys(buf, "G?^abcd\<CR>Y")
+  call term_sendkeys(buf, "kkP")
+  call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_changed_1', {})
+
   call StopVimInTerminal(buf)
   call delete('Xhlsearch_cursearch')
 endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    5047,
+/**/
     5046,
 /**/
     5045,