aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-06-19 07:42:56 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-06-19 08:02:29 +0800
commita2a3e8412e6d4e9a952c57a5298016cae8bf5229 (patch)
tree4c606a997f28a74b531ab2888e2f59eac5329d70
parent14aba679670a6485596c60fa5eb1df92ecae8a1b (diff)
downloadrneovim-a2a3e8412e6d4e9a952c57a5298016cae8bf5229.tar.gz
rneovim-a2a3e8412e6d4e9a952c57a5298016cae8bf5229.tar.bz2
rneovim-a2a3e8412e6d4e9a952c57a5298016cae8bf5229.zip
vim-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. https://github.com/vim/vim/commit/368137aa525982984beed73940af481ac53a62af Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r--src/nvim/change.c4
-rw-r--r--src/nvim/drawscreen.c13
-rw-r--r--src/nvim/drawscreen.h6
-rw-r--r--src/nvim/match.c3
-rw-r--r--test/functional/ui/searchhl_spec.lua25
-rw-r--r--test/old/testdir/test_search.vim5
6 files changed, 54 insertions, 2 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 6c979df1fe..428a9187c8 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -392,6 +392,10 @@ static void changed_common(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnum
}
}
}
+
+ if (wp == curwin && xtra != 0 && search_hl_has_cursor_lnum >= lnum) {
+ search_hl_has_cursor_lnum += xtra;
+ }
}
// Call update_screen() later, which checks out what needs to be redrawn,
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 88e1f302da..770f8da6cf 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -1593,6 +1593,18 @@ static void win_update(win_T *wp)
}
}
}
+
+ 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;
+ }
+ }
+
if (mod_top != 0 && hasAnyFolding(wp)) {
// A change in a line can cause lines above it to become folded or
// unfolded. Find the top most buffer line that may be affected.
@@ -1651,6 +1663,7 @@ static void win_update(win_T *wp)
wp->w_redraw_top = 0; // reset for next time
wp->w_redraw_bot = 0;
+ search_hl_has_cursor_lnum = 0;
// When only displaying the lines at the top, set top_end. Used when
// window has scrolled down for msg_scrolled.
diff --git a/src/nvim/drawscreen.h b/src/nvim/drawscreen.h
index f804345bca..36ba8099fd 100644
--- a/src/nvim/drawscreen.h
+++ b/src/nvim/drawscreen.h
@@ -25,7 +25,11 @@ EXTERN bool updating_screen INIT( = false);
/// must_redraw to be set.
EXTERN bool redraw_not_allowed INIT( = false);
-EXTERN match_T screen_search_hl INIT( = { 0 }); ///< used for 'hlsearch' highlight matching
+/// used for 'hlsearch' highlight matching
+EXTERN match_T screen_search_hl INIT( = { 0 });
+
+/// last lnum where CurSearch was displayed
+EXTERN linenr_T search_hl_has_cursor_lnum INIT( = 0);
#define W_ENDCOL(wp) ((wp)->w_wincol + (wp)->w_width)
#define W_ENDROW(wp) ((wp)->w_winrow + (wp)->w_height)
diff --git a/src/nvim/match.c b/src/nvim/match.c
index 6ae4e41147..86cab5221d 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -706,6 +706,9 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T
// group.
if (shl == search_hl && shl->has_cursor) {
shl->attr_cur = win_hl_attr(wp, HLF_LC);
+ if (shl->attr_cur != shl->attr) {
+ search_hl_has_cursor_lnum = lnum;
+ }
} else {
shl->attr_cur = shl->attr;
}
diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua
index 493493da60..eab265cbb1 100644
--- a/test/functional/ui/searchhl_spec.lua
+++ b/test/functional/ui/searchhl_spec.lua
@@ -197,7 +197,8 @@ describe('search highlighting', function()
}
end)
- it('works for multiline match', function()
+ -- oldtest: Test_hlsearch_cursearch()
+ it('works for multiline match, no duplicate highlight', function()
command([[call setline(1, ['one', 'foo', 'bar', 'baz', 'foo the foo and foo', 'bar'])]])
feed('gg/foo<CR>')
screen:expect([[
@@ -281,6 +282,28 @@ describe('search highlighting', function()
{2:hij}kl |
/efg\nhij |
]])
+
+ -- check clearing CurSearch when using it for another match
+ feed('G?^abcd<CR>Y')
+ screen:expect([[
+ --- |
+ {1:abcd}efg |
+ hijkl |
+ --- |
+ {2:^abcd}efg |
+ hijkl |
+ ?^abcd |
+ ]])
+ feed('kkP')
+ screen:expect([[
+ --- |
+ {1:abcd}efg |
+ {2:^abcd}efg |
+ hijkl |
+ --- |
+ {1:abcd}efg |
+ ?^abcd |
+ ]])
end)
end)
diff --git a/test/old/testdir/test_search.vim b/test/old/testdir/test_search.vim
index 018ee7ad5a..8b535b5b19 100644
--- a/test/old/testdir/test_search.vim
+++ b/test/old/testdir/test_search.vim
@@ -1094,6 +1094,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