diff src/match.c @ 28399:d395fadbaf67 v8.2.4724

patch 8.2.4724: current instance of last search pattern not easily spotted Commit: https://github.com/vim/vim/commit/a43993897aa372159f682df37562f159994dc85c Author: LemonBoy <thatlemon@gmail.com> Date: Sat Apr 9 21:04:08 2022 +0100 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 https://github.com/vim/vim/issues/10133)
author Bram Moolenaar <Bram@vim.org>
date Sat, 09 Apr 2022 22:15:03 +0200
parents 62cc3b60493b
children 9ff0e5a29037
line wrap: on
line diff
--- a/src/match.c
+++ b/src/match.c
@@ -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)
 	    {