# HG changeset patch # User Bram Moolenaar # Date 1654001103 -7200 # Node ID a2710736125af9ccc3895212aeb41410f505fd9f # Parent 947c2f51b6f7fbf29210ab3997ddf286c7e92ec4 patch 8.2.5047: CurSearch highlight is often wrong Commit: https://github.com/vim/vim/commit/368137aa525982984beed73940af481ac53a62af Author: Bram Moolenaar 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. diff --git a/src/change.c b/src/change.c --- 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, diff --git a/src/drawscreen.c b/src/drawscreen.c --- 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. diff --git a/src/globals.h b/src/globals.h --- 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); diff --git a/src/match.c b/src/match.c --- 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) diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_changed_1.dump b/src/testdir/dumps/Test_hlsearch_cursearch_changed_1.dump 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࿈ff13|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| diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim --- 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\") call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line_5', {}) + " check clearing CurSearch when using it for another match + call term_sendkeys(buf, "G?^abcd\Y") + call term_sendkeys(buf, "kkP") + call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_changed_1', {}) + call StopVimInTerminal(buf) call delete('Xhlsearch_cursearch') endfunc diff --git a/src/version.c b/src/version.c --- 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,