aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-10-01 21:29:54 +0800
committerGitHub <noreply@github.com>2022-10-01 21:29:54 +0800
commit9353e2f7ef6d0919257548e1a43988404900bf03 (patch)
tree6752438c054b2f41af73c1a631857a4714acaf2b
parente54541f7f941427b408f8d5a7bab446c141b5f76 (diff)
downloadrneovim-9353e2f7ef6d0919257548e1a43988404900bf03.tar.gz
rneovim-9353e2f7ef6d0919257548e1a43988404900bf03.tar.bz2
rneovim-9353e2f7ef6d0919257548e1a43988404900bf03.zip
vim-patch:8.2.2542: highlight of char beyond line end is not correct (#20424)
Problem: Highlight of char beyond line end is not correct. (Chuan Wei Foo) Solution: Fix counting NUL as one cell. Draw one more character if the EOL is part of the match. (closes vim/vim#7883) https://github.com/vim/vim/commit/41f0895c6e3c7b921e3c102ad42be52b1be48018 Reorder test_search.vim to match Vim.
-rw-r--r--src/nvim/match.c20
-rw-r--r--src/nvim/testdir/test_search.vim76
-rw-r--r--test/functional/legacy/search_spec.lua30
-rw-r--r--test/functional/ui/searchhl_spec.lua22
4 files changed, 104 insertions, 44 deletions
diff --git a/src/nvim/match.c b/src/nvim/match.c
index cd8c65cc02..f41eab889b 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -738,7 +738,13 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match
if (shl->startcol == shl->endcol) {
// highlight empty match, try again after it
- shl->endcol += utfc_ptr2len((char *)(*line) + shl->endcol);
+ char *p = (char *)(*line) + shl->endcol;
+
+ if (*p == NUL) {
+ shl->endcol++;
+ } else {
+ shl->endcol += utfc_ptr2len(p);
+ }
}
// Loop to check if the match starts at the
@@ -792,12 +798,19 @@ bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol)
prevcol++;
}
- if (!search_hl->is_addpos && prevcol == search_hl->startcol) {
+ // Highlight a character after the end of the line if the match started
+ // at the end of the line or when the match continues in the next line
+ // (match includes the line break).
+ if (!search_hl->is_addpos && (prevcol == (long)search_hl->startcol
+ || (prevcol > (long)search_hl->startcol
+ && search_hl->endcol == MAXCOL))) {
return true;
} else {
cur = wp->w_match_head;
while (cur != NULL) {
- if (!cur->hl.is_addpos && prevcol == cur->hl.startcol) {
+ if (!cur->hl.is_addpos && (prevcol == (long)cur->hl.startcol
+ || (prevcol > (long)cur->hl.startcol
+ && cur->hl.endcol == MAXCOL))) {
return true;
}
cur = cur->next;
@@ -815,7 +828,6 @@ void get_search_match_hl(win_T *wp, match_T *search_hl, long col, int *char_attr
bool shl_flag = false; // flag to indicate whether search_hl
// has been processed or not
- *char_attr = search_hl->attr;
while (cur != NULL || !shl_flag) {
if (!shl_flag
&& (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) {
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index 3d1bbfb726..0cf55c7d0b 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -956,24 +956,24 @@ func Test_incsearch_search_dump()
call delete('Xis_search_script')
endfunc
-func Test_hlsearch_block_visual_match()
+func Test_hlsearch_dump()
+ CheckOption hlsearch
CheckScreendump
- let lines =<< trim END
- set hlsearch
- call setline(1, ['aa', 'bbbb', 'cccccc'])
- END
- call writefile(lines, 'Xhlsearch_block')
- let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60})
+ call writefile([
+ \ 'set hlsearch cursorline',
+ \ 'call setline(1, ["xxx", "xxx", "xxx"])',
+ \ '/.*',
+ \ '2',
+ \ ], 'Xhlsearch_script')
+ let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50})
+ call VerifyScreenDump(buf, 'Test_hlsearch_1', {})
- call term_sendkeys(buf, "G\<C-V>$kk\<Esc>")
- sleep 100m
- call term_sendkeys(buf, "/\\%V\<CR>")
- sleep 100m
- call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {})
+ call term_sendkeys(buf, "/\\_.*\<CR>")
+ call VerifyScreenDump(buf, 'Test_hlsearch_2', {})
call StopVimInTerminal(buf)
- call delete('Xhlsearch_block')
+ call delete('Xhlsearch_script')
endfunc
func Test_hlsearch_and_visual()
@@ -996,6 +996,26 @@ func Test_hlsearch_and_visual()
call delete('Xhlvisual_script')
endfunc
+func Test_hlsearch_block_visual_match()
+ CheckScreendump
+
+ let lines =<< trim END
+ set hlsearch
+ call setline(1, ['aa', 'bbbb', 'cccccc'])
+ END
+ call writefile(lines, 'Xhlsearch_block')
+ let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60})
+
+ call term_sendkeys(buf, "G\<C-V>$kk\<Esc>")
+ sleep 100m
+ call term_sendkeys(buf, "/\\%V\<CR>")
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {})
+
+ call StopVimInTerminal(buf)
+ call delete('Xhlsearch_block')
+endfunc
+
func Test_incsearch_substitute()
CheckFunction test_override
CheckOption incsearch
@@ -1017,6 +1037,21 @@ func Test_incsearch_substitute()
call Incsearch_cleanup()
endfunc
+func Test_incsearch_substitute_long_line()
+ CheckFunction test_override
+ new
+ call test_override("char_avail", 1)
+ set incsearch
+
+ call repeat('x', 100000)->setline(1)
+ call feedkeys(':s/\%c', 'xt')
+ redraw
+ call feedkeys("\<Esc>", 'xt')
+
+ call Incsearch_cleanup()
+ bwipe!
+endfunc
+
func Test_hlsearch_cursearch()
CheckScreendump
@@ -1341,21 +1376,6 @@ func Test_subst_word_under_cursor()
set noincsearch
endfunc
-func Test_incsearch_substitute_long_line()
- CheckFunction test_override
- new
- call test_override("char_avail", 1)
- set incsearch
-
- call repeat('x', 100000)->setline(1)
- call feedkeys(':s/\%c', 'xt')
- redraw
- call feedkeys("\<Esc>", 'xt')
-
- call Incsearch_cleanup()
- bwipe!
-endfunc
-
func Test_search_undefined_behaviour()
CheckFeature terminal
diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua
index 67991f5d48..5a94fca794 100644
--- a/test/functional/legacy/search_spec.lua
+++ b/test/functional/legacy/search_spec.lua
@@ -644,7 +644,35 @@ end)
describe('Search highlight', function()
before_each(clear)
- it('Search highlight is combined with Visual highlight vim-patch:8.2.2797', function()
+
+ -- oldtest: Test_hlsearch_dump()
+ it('beyond line end vim-patch:8.2.2542', function()
+ local screen = Screen.new(50, 6)
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [2] = {background = Screen.colors.Yellow}, -- Search
+ [3] = {background = Screen.colors.Grey90}, -- CursorLine
+ })
+ screen:attach()
+ exec([[
+ set hlsearch noincsearch cursorline
+ call setline(1, ["xxx", "xxx", "xxx"])
+ /.*
+ 2
+ ]])
+ feed([[/\_.*<CR>]])
+ screen:expect([[
+ {2:xxx } |
+ {2:xxx } |
+ {2:^xxx }{3: }|
+ {1:~ }|
+ {1:~ }|
+ /\_.* |
+ ]])
+ end)
+
+ -- oldtest: Test_hlsearch_and_visual()
+ it('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
diff --git a/test/functional/ui/searchhl_spec.lua b/test/functional/ui/searchhl_spec.lua
index c5c88323a2..18bbb56a61 100644
--- a/test/functional/ui/searchhl_spec.lua
+++ b/test/functional/ui/searchhl_spec.lua
@@ -221,10 +221,10 @@ describe('search highlighting', function()
feed('gg/foo\\nbar<CR>')
screen:expect([[
one |
- {2:^foo} |
+ {2:^foo } |
{2:bar} |
baz |
- {1:foo} |
+ {1:foo } |
{1:bar} |
/foo\nbar |
]])
@@ -232,20 +232,20 @@ describe('search highlighting', function()
feed('gg/efg\\nhij<CR>')
screen:expect([[
--- |
- abcd{2:^efg} |
+ abcd{2:^efg } |
{2:hij}kl |
--- |
- abcd{1:efg} |
+ abcd{1:efg } |
{1:hij}kl |
/efg\nhij |
]])
feed('n')
screen:expect([[
--- |
- abcd{1:efg} |
+ abcd{1:efg } |
{1:hij}kl |
--- |
- abcd{2:^efg} |
+ abcd{2:^efg } |
{2:hij}kl |
/efg\nhij |
]])
@@ -548,9 +548,9 @@ describe('search highlighting', function()
feed('/line\\na<cr>')
screen:expect([[
|
- a repeated {2:^line} |
- {2:a} repeated {2:line} |
- {2:a} repeated {2:line} |
+ a repeated {2:^line } |
+ {2:a} repeated {2:line } |
+ {2:a} repeated {2:line } |
{2:a} repeated line |
{1:~ }|
{4:search hit BOTTOM, continuing at TOP} |
@@ -560,9 +560,9 @@ describe('search highlighting', function()
feed('4Grb')
screen:expect([[
|
- a repeated {2:line} |
+ a repeated {2:line } |
{2:a} repeated line |
- ^b repeated {2:line} |
+ ^b repeated {2:line } |
{2:a} repeated line |
{1:~ }|
{4:search hit BOTTOM, continuing at TOP} |