]> granicus.if.org Git - vim/commitdiff
patch 8.2.5047: CurSearch highlight is often wrong v8.2.5047
authorBram Moolenaar <Bram@vim.org>
Tue, 31 May 2022 12:43:12 +0000 (13:43 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 31 May 2022 12:43:12 +0000 (13:43 +0100)
Problem:    CurSearch highlight is often wrong.
Solution:   Remember the last highlighted position and redraw when needed.

src/change.c
src/drawscreen.c
src/globals.h
src/match.c
src/testdir/dumps/Test_hlsearch_cursearch_changed_1.dump [new file with mode: 0644]
src/testdir/test_search.vim
src/version.c

index a9927e0fdef33c2ccf6eda1b46a49beb677bf6fc..ed1f3a302b1d1de0ccde1644b15f1ac34c4db235 100644 (file)
@@ -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,
index 2838bf88cf4182747467129f5726b0aa07f07f5d..ed8927127e46dcf2512739b84e4e691c321a46d3 100644 (file)
@@ -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.
index 3861e80680f9f4cb53e3e728bc59238c33ab3698..7100dcd08d0e185dfe5de0385883d3a8b1b62864 100644 (file)
@@ -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);
index 1078424af27d16e30986820463c89624fbb391e4..8280da7d572280a9320648c71209f3ec15e8aea1 100644 (file)
@@ -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 (file)
index 0000000..607e079
--- /dev/null
@@ -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| 
index 2a767c0c372da153cda1f29a718f4f272fe1f802..e1a62bd9300e8c62b7df4f1a752e337cc9b4268f 100644 (file)
@@ -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
index b7693de1a14944749826743b0afcdea4c32ad27f..db2a5b22c7fb9ad1ad79b5b6faa2a5a7dc1d3acb 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5047,
 /**/
     5046,
 /**/