]> granicus.if.org Git - vim/commitdiff
patch 8.2.4724: current instance of last search pattern not easily spotted v8.2.4724
authorLemonBoy <thatlemon@gmail.com>
Sat, 9 Apr 2022 20:04:08 +0000 (21:04 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 9 Apr 2022 20:04:08 +0000 (21:04 +0100)
Problem:    Current instance of last search pattern not easily spotted.
Solution:   Add CurSearch highlighting. (closes #10133)

14 files changed:
runtime/doc/options.txt
runtime/doc/syntax.txt
src/highlight.c
src/match.c
src/normal.c
src/optiondefs.h
src/structs.h
src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump [new file with mode: 0644]
src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump [new file with mode: 0644]
src/testdir/dumps/Test_hlsearch_cursearch_single_line_3.dump [new file with mode: 0644]
src/testdir/test_search.vim
src/version.c
src/vim.h

index 443175a85674c2421c5b261c19918252d55bd1ea..ddd5af08edf6d7de8a6467446877c7e3933b539e 100644 (file)
@@ -4165,6 +4165,7 @@ A jump table for the options with a short description can be found at |Q_op|.
        |hl-ErrorMsg|    e  error messages
                         h  (obsolete, ignored)
        |hl-IncSearch|   i  'incsearch' highlighting
+       |hl-CurSearch|   y  current instance of last search pattern
        |hl-Search|      l  last search pattern highlighting (see 'hlsearch')
        |hl-MoreMsg|     m  |more-prompt|
        |hl-ModeMsg|     M  Mode (e.g., "-- INSERT --")
index 826a0b47aa3bc6ce44bddddbd371db64bcd183d8..dfb0fb77581f419671fc769765790a50f1e8a74b 100644 (file)
@@ -5318,6 +5318,8 @@ QuickFixLine      Current |quickfix| item in the quickfix window.
                                                        *hl-Search*
 Search         Last search pattern highlighting (see 'hlsearch').
                Also used for similar items that need to stand out.
+                                                       *hl-CurSearch*
+CurSearch      Current match for the last search pattern (see 'hlsearch').
                                                        *hl-SpecialKey*
 SpecialKey     Meta and special keys listed with ":map", also for text used
                to show unprintable characters in the text, 'listchars'.
index 724c4ba8d7b8a96c3b964b0428b7f6dde2491328..61fea9a6696d2ac2e30528d6a7377761c663ff0d 100644 (file)
@@ -157,6 +157,7 @@ static char *(highlight_init_both[]) = {
     "default link QuickFixLine Search",
     "default link CursorLineSign SignColumn",
     "default link CursorLineFold FoldColumn",
+    "default link CurSearch Search",
     CENT("Normal cterm=NONE", "Normal gui=NONE"),
     NULL
 };
index ce35bacb8c8f0472cd2e154e3c513fc7982e07f5..d74d8d73ff3bf3593d97079c5ab1c3325109860d 100644 (file)
@@ -652,6 +652,7 @@ prepare_search_hl_line(
            shl = &cur->hl;
        shl->startcol = MAXCOL;
        shl->endcol = MAXCOL;
+       shl->lines = 0;
        shl->attr_cur = 0;
        shl->is_addpos = FALSE;
        if (cur != NULL)
@@ -674,6 +675,10 @@ prepare_search_hl_line(
                shl->endcol = shl->rm.endpos[0].col;
            else
                shl->endcol = MAXCOL;
+           if (shl->rm.endpos[0].lnum != shl->rm.startpos[0].lnum)
+               shl->lines = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
+           else
+               shl->lines = 1;
            // Highlight one character for an empty match.
            if (shl->startcol == shl->endcol)
            {
@@ -768,6 +773,17 @@ update_search_hl(
                else
                    *has_match_conc = 0;
 # endif
+               // Highlight the match were the cursor is using the CurSearch
+               // group.
+               if (shl == search_hl
+                       && wp->w_cursor.lnum >= shl->lnum
+                       && wp->w_cursor.lnum < shl->lnum + shl->lines
+                       && wp->w_cursor.col >= shl->startcol
+                       && wp->w_cursor.col < shl->endcol)
+               {
+                   shl->attr_cur = HL_ATTR(HLF_LC);
+               }
+
            }
            else if (col == shl->endcol)
            {
index d7a2857146a7290dc53d9f8b12688b872251d093..b5b04484385027dc4e61ef9ce6d4802b6f801a5b 100644 (file)
@@ -4153,6 +4153,7 @@ nv_search(cmdarg_T *cap)
                                                      ? 0 : SEARCH_MARK, NULL);
 }
 
+
 /*
  * Handle "N" and "n" commands.
  * cap->arg is SEARCH_REV for "N", 0 for "n".
@@ -4173,6 +4174,12 @@ nv_next(cmdarg_T *cap)
        (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg, NULL);
        cap->count1 -= 1;
     }
+
+#ifdef FEAT_SEARCH_EXTRA
+    // Redraw the window to refresh the highlighted matches.
+    if (i > 0 && p_hls && !no_hlsearch)
+       redraw_later(SOME_VALID);
+#endif
 }
 
 /*
@@ -4190,6 +4197,7 @@ normal_search(
 {
     int                i;
     searchit_arg_T sia;
+    pos_T      prev_cursor = curwin->w_cursor;
 
     cap->oap->motion_type = MCHAR;
     cap->oap->inclusive = FALSE;
@@ -4213,6 +4221,11 @@ normal_search(
            foldOpenCursor();
 #endif
     }
+#ifdef FEAT_SEARCH_EXTRA
+    // Redraw the window to refresh the highlighted matches.
+    if (!EQUAL_POS(curwin->w_cursor, prev_cursor) && p_hls && !no_hlsearch)
+       redraw_later(SOME_VALID);
+#endif
 
     // "/$" will put the cursor after the end of the line, may need to
     // correct that here
index 54cccf83eb74dd17153ff38df18cea2479ba9517..bce677f8295e76417f38a2f5ff3278623d0bc2c7 100644 (file)
@@ -299,7 +299,7 @@ struct vimoption
 # define ISP_LATIN1 (char_u *)"@,161-255"
 #endif
 
-# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,G:CursorLineSign,O:CursorLineFold,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
+# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,y:CurSearch,m:MoreMsg,M:ModeMsg,n:LineNr,a:LineNrAbove,b:LineNrBelow,N:CursorLineNr,G:CursorLineSign,O:CursorLineFold,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
 
 // Default python version for pyx* commands
 #if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
index 738c592314f9297df43b9458d8f84ca973bb1e67..5ad606efe84b57c4ab8550cb4811c5f99c2c70ee 100644 (file)
@@ -3329,6 +3329,7 @@ typedef struct
                            // found match (may continue in next line)
     buf_T      *buf;       // the buffer to search for a match
     linenr_T   lnum;       // the line to search for a match
+    linenr_T   lines;      // number of lines starting from lnum
     int                attr;       // attributes to be used for a match
     int                attr_cur;   // attributes currently active in win_line()
     linenr_T   first_lnum; // first lnum to search for multi-line pat
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump b/src/testdir/dumps/Test_hlsearch_cursearch_multiple_line.dump
new file mode 100644 (file)
index 0000000..950ffef
--- /dev/null
@@ -0,0 +1,9 @@
+|o+0&#ffffff0|n|e| @56
+>f+0&#4040ff13|o@1| | +0&#ffffff0@55
+|b+0&#4040ff13|a|r| +0&#ffffff0@56
+|b|a|z| @56
+|f+0&#ffff4012|o@1| | +0&#ffffff0@55
+|b+0&#ffff4012|a|r| +0&#ffffff0@56
+|~+0#4040ff13&| @58
+|~| @58
+|/+0#0000000&|f|o@1|\|n|b|a|r| @32|2|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump b/src/testdir/dumps/Test_hlsearch_cursearch_single_line_1.dump
new file mode 100644 (file)
index 0000000..ef2922f
--- /dev/null
@@ -0,0 +1,9 @@
+|o+0&#ffffff0|n|e| @56
+>f+0&#4040ff13|o@1| +0&#ffffff0@56
+|b|a|r| @56
+|b|a|z| @56
+|f+0&#ffff4012|o@1| +0&#ffffff0@56
+|b|a|r| @56
+|~+0#4040ff13&| @58
+|~| @58
+|/+0#0000000&|f|o@1| @37|2|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump b/src/testdir/dumps/Test_hlsearch_cursearch_single_line_2.dump
new file mode 100644 (file)
index 0000000..26e03e0
--- /dev/null
@@ -0,0 +1,9 @@
+|o+0&#ffffff0|n|e| @56
+|f+0&#ffff4012|o@1| +0&#ffffff0@56
+|b|a|r| @56
+|b|a|z| @56
+>f+0&#4040ff13|o@1| +0&#ffffff0@56
+|b|a|r| @56
+|~+0#4040ff13&| @58
+|~| @58
+|/+0#0000000&|f|o@1| @37|5|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_hlsearch_cursearch_single_line_3.dump b/src/testdir/dumps/Test_hlsearch_cursearch_single_line_3.dump
new file mode 100644 (file)
index 0000000..b0c38c2
--- /dev/null
@@ -0,0 +1,9 @@
+|o+0&#ffffff0|n|e| @56
+>f+0&#4040ff13|o@1| +0&#ffffff0@56
+|b|a|r| @56
+|b|a|z| @56
+|f+0&#ffff4012|o@1| +0&#ffffff0@56
+|b|a|r| @56
+|~+0#4040ff13&| @58
+|~| @58
+|?+0#0000000&|f|o@1| @37|2|,|1| @10|A|l@1| 
index f790c84557a888a16f8e9caf6b1f10a3a6def81a..4ed249d39ddae1b7270cb803c5edda12f7b497bc 100644 (file)
@@ -1038,6 +1038,34 @@ func Test_incsearch_substitute_long_line()
   bwipe!
 endfunc
 
+func Test_hlsearch_cursearch()
+  CheckScreendump
+
+  let lines =<< trim END
+    set hlsearch scrolloff=0
+    call setline(1, ['one', 'foo', 'bar', 'baz', 'foo', 'bar'])
+    hi Search ctermbg=yellow
+    hi CurSearch ctermbg=blue
+  END
+  call writefile(lines, 'Xhlsearch_cursearch')
+  let buf = RunVimInTerminal('-S Xhlsearch_cursearch', {'rows': 9, 'cols': 60})
+
+  call term_sendkeys(buf, "gg/foo\<CR>")
+  call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_1', {})
+
+  call term_sendkeys(buf, "n")
+  call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_2', {})
+
+  call term_sendkeys(buf, "?\<CR>")
+  call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_single_line_3', {})
+
+  call term_sendkeys(buf, "gg/foo\\nbar\<CR>")
+  call VerifyScreenDump(buf, 'Test_hlsearch_cursearch_multiple_line', {})
+
+  call StopVimInTerminal(buf)
+  call delete('Xhlsearch_cursearch')
+endfunc
+
 " Similar to Test_incsearch_substitute() but with a screendump halfway.
 func Test_incsearch_substitute_dump()
   CheckOption incsearch
index 574bacbaa61eb659db874096433e6b1f4f4835c2..ecf846152bd14f2443b5e10f672d6ab570cc8c80 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4724,
 /**/
     4723,
 /**/
index f448ad010cd205557f339268624281ba6a0b5298..f9ec6e54a7fea20bbcefff628da0ba68908c20c0 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1410,6 +1410,7 @@ typedef enum
     , HLF_H        // obsolete, ignored
     , HLF_I        // incremental search
     , HLF_L        // last search string
+    , HLF_LC       // last search string under cursor
     , HLF_M        // "--More--" message
     , HLF_CM       // Mode (e.g., "-- INSERT --")
     , HLF_N        // line number for ":number" and ":#" commands
@@ -1457,7 +1458,7 @@ typedef enum
 
 // The HL_FLAGS must be in the same order as the HLF_ enums!
 // When changing this also adjust the default for 'highlight'.
-#define HL_FLAGS {'8', '~', '@', 'd', 'e', 'h', 'i', 'l', 'm', 'M', \
+#define HL_FLAGS {'8', '~', '@', 'd', 'e', 'h', 'i', 'l', 'y', 'm', 'M', \
                  'n', 'a', 'b', 'N', 'G', 'O', 'r', 's', 'S', 'c', 't', 'v', 'V', \
                  'w', 'W', 'f', 'F', 'A', 'C', 'D', 'T', '-', '>', \
                  'B', 'P', 'R', 'L', \