aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-05-13 21:20:15 +0800
committerGitHub <noreply@github.com>2022-05-13 21:20:15 +0800
commitc196119acbd5de0e9e5fae91db62fc9dfc675f8d (patch)
tree89e19a4134ac5cc097cded4f64d4b1094109ffaf
parent2875d45e79b80878af45c91702914f4f0d0e3dca (diff)
downloadrneovim-c196119acbd5de0e9e5fae91db62fc9dfc675f8d.tar.gz
rneovim-c196119acbd5de0e9e5fae91db62fc9dfc675f8d.tar.bz2
rneovim-c196119acbd5de0e9e5fae91db62fc9dfc675f8d.zip
vim-patch:8.2.2797: Search highlight disappears in the Visual area (#17947)
Problem: Search highlight disappears in the Visual area. Solution: Combine the search attributes. (closes vim/vim#8134) https://github.com/vim/vim/commit/2d5f385cee3668c44089edcb9d60b0b5d751ee5d
-rw-r--r--src/nvim/screen.c4
-rw-r--r--src/nvim/testdir/test_search.vim20
-rw-r--r--test/functional/legacy/search_spec.lua32
3 files changed, 56 insertions, 0 deletions
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 36e8f11bbb..003230d110 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -3006,6 +3006,10 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
if (area_attr != 0) {
char_attr = hl_combine_attr(line_attr, area_attr);
+ if (!highlight_match) {
+ // let search highlight show in Visual area if possible
+ char_attr = hl_combine_attr(search_attr, char_attr);
+ }
} else if (search_attr != 0) {
char_attr = hl_combine_attr(line_attr, search_attr);
}
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index d359e69f91..454c956996 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -925,6 +925,26 @@ func Test_hlsearch_block_visual_match()
call delete('Xhlsearch_block')
endfunc
+func Test_hlsearch_and_visual()
+ CheckOption hlsearch
+ CheckScreendump
+
+ call writefile([
+ \ 'set hlsearch',
+ \ 'call setline(1, repeat(["xxx yyy zzz"], 3))',
+ \ 'hi Search cterm=bold',
+ \ '/yyy',
+ \ 'call cursor(1, 6)',
+ \ ], 'Xhlvisual_script')
+ let buf = RunVimInTerminal('-S Xhlvisual_script', {'rows': 6, 'cols': 40})
+ call term_sendkeys(buf, "vjj")
+ call VerifyScreenDump(buf, 'Test_hlsearch_visual_1', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call StopVimInTerminal(buf)
+ call delete('Xhlvisual_script')
+endfunc
+
func Test_incsearch_substitute()
CheckFunction test_override
CheckOption incsearch
diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua
index 4ed08881de..67991f5d48 100644
--- a/test/functional/legacy/search_spec.lua
+++ b/test/functional/legacy/search_spec.lua
@@ -7,6 +7,7 @@ local eval = helpers.eval
local feed = helpers.feed
local funcs = helpers.funcs
local poke_eventloop = helpers.poke_eventloop
+local exec = helpers.exec
describe('search cmdline', function()
local screen
@@ -640,3 +641,34 @@ describe('search cmdline', function()
feed('<esc>')
end)
end)
+
+describe('Search highlight', function()
+ before_each(clear)
+ it('Search highlight is combined with Visual highlight vim-patch:8.2.2797', function()
+ local screen = Screen.new(40, 6)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [2] = {bold = true}, -- ModeMsg, Search
+ [3] = {background = Screen.colors.LightGrey}, -- Visual
+ [4] = {background = Screen.colors.Yellow, bold = true}, -- Search
+ [5] = {background = Screen.colors.LightGrey, bold = true}, -- Visual + Search
+ })
+ screen:attach()
+ exec([[
+ set hlsearch noincsearch
+ call setline(1, repeat(["xxx yyy zzz"], 3))
+ hi Search gui=bold
+ /yyy
+ call cursor(1, 6)
+ ]])
+ feed('vjj')
+ screen:expect([[
+ xxx {4:y}{5:yy}{3: zzz} |
+ {3:xxx }{5:yyy}{3: zzz} |
+ {3:xxx }{5:y}{4:^yy} zzz |
+ {1:~ }|
+ {1:~ }|
+ {2:-- VISUAL --} |
+ ]])
+ end)
+end)