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)
41f0895c6e

Reorder test_search.vim to match Vim.
This commit is contained in:
zeertzjq 2022-10-01 21:29:54 +08:00 committed by GitHub
parent e54541f7f9
commit 9353e2f7ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 44 deletions

View File

@ -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) { if (shl->startcol == shl->endcol) {
// highlight empty match, try again after it // 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 // 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++; 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; return true;
} else { } else {
cur = wp->w_match_head; cur = wp->w_match_head;
while (cur != NULL) { 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; return true;
} }
cur = cur->next; 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 bool shl_flag = false; // flag to indicate whether search_hl
// has been processed or not // has been processed or not
*char_attr = search_hl->attr;
while (cur != NULL || !shl_flag) { while (cur != NULL || !shl_flag) {
if (!shl_flag if (!shl_flag
&& (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) { && (cur == NULL || cur->priority > SEARCH_HL_PRIORITY)) {

View File

@ -956,24 +956,24 @@ func Test_incsearch_search_dump()
call delete('Xis_search_script') call delete('Xis_search_script')
endfunc endfunc
func Test_hlsearch_block_visual_match() func Test_hlsearch_dump()
CheckOption hlsearch
CheckScreendump CheckScreendump
let lines =<< trim END call writefile([
set hlsearch \ 'set hlsearch cursorline',
call setline(1, ['aa', 'bbbb', 'cccccc']) \ 'call setline(1, ["xxx", "xxx", "xxx"])',
END \ '/.*',
call writefile(lines, 'Xhlsearch_block') \ '2',
let buf = RunVimInTerminal('-S Xhlsearch_block', {'rows': 9, 'cols': 60}) \ ], '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>") call term_sendkeys(buf, "/\\_.*\<CR>")
sleep 100m call VerifyScreenDump(buf, 'Test_hlsearch_2', {})
call term_sendkeys(buf, "/\\%V\<CR>")
sleep 100m
call VerifyScreenDump(buf, 'Test_hlsearch_block_visual_match', {})
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
call delete('Xhlsearch_block') call delete('Xhlsearch_script')
endfunc endfunc
func Test_hlsearch_and_visual() func Test_hlsearch_and_visual()
@ -996,6 +996,26 @@ func Test_hlsearch_and_visual()
call delete('Xhlvisual_script') call delete('Xhlvisual_script')
endfunc 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() func Test_incsearch_substitute()
CheckFunction test_override CheckFunction test_override
CheckOption incsearch CheckOption incsearch
@ -1017,6 +1037,21 @@ func Test_incsearch_substitute()
call Incsearch_cleanup() call Incsearch_cleanup()
endfunc 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() func Test_hlsearch_cursearch()
CheckScreendump CheckScreendump
@ -1341,21 +1376,6 @@ func Test_subst_word_under_cursor()
set noincsearch set noincsearch
endfunc 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() func Test_search_undefined_behaviour()
CheckFeature terminal CheckFeature terminal

View File

@ -644,7 +644,35 @@ end)
describe('Search highlight', function() describe('Search highlight', function()
before_each(clear) 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) local screen = Screen.new(40, 6)
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText

View File

@ -221,10 +221,10 @@ describe('search highlighting', function()
feed('gg/foo\\nbar<CR>') feed('gg/foo\\nbar<CR>')
screen:expect([[ screen:expect([[
one | one |
{2:^foo} | {2:^foo } |
{2:bar} | {2:bar} |
baz | baz |
{1:foo} | {1:foo } |
{1:bar} | {1:bar} |
/foo\nbar | /foo\nbar |
]]) ]])
@ -232,20 +232,20 @@ describe('search highlighting', function()
feed('gg/efg\\nhij<CR>') feed('gg/efg\\nhij<CR>')
screen:expect([[ screen:expect([[
--- | --- |
abcd{2:^efg} | abcd{2:^efg } |
{2:hij}kl | {2:hij}kl |
--- | --- |
abcd{1:efg} | abcd{1:efg } |
{1:hij}kl | {1:hij}kl |
/efg\nhij | /efg\nhij |
]]) ]])
feed('n') feed('n')
screen:expect([[ screen:expect([[
--- | --- |
abcd{1:efg} | abcd{1:efg } |
{1:hij}kl | {1:hij}kl |
--- | --- |
abcd{2:^efg} | abcd{2:^efg } |
{2:hij}kl | {2:hij}kl |
/efg\nhij | /efg\nhij |
]]) ]])
@ -548,9 +548,9 @@ describe('search highlighting', function()
feed('/line\\na<cr>') feed('/line\\na<cr>')
screen:expect([[ screen:expect([[
| |
a repeated {2:^line} | a repeated {2:^line } |
{2:a} repeated {2:line} | {2:a} repeated {2:line } |
{2:a} repeated {2:line} | {2:a} repeated {2:line } |
{2:a} repeated line | {2:a} repeated line |
{1:~ }| {1:~ }|
{4:search hit BOTTOM, continuing at TOP} | {4:search hit BOTTOM, continuing at TOP} |
@ -560,9 +560,9 @@ describe('search highlighting', function()
feed('4Grb') feed('4Grb')
screen:expect([[ screen:expect([[
| |
a repeated {2:line} | a repeated {2:line } |
{2:a} repeated line | {2:a} repeated line |
^b repeated {2:line} | ^b repeated {2:line } |
{2:a} repeated line | {2:a} repeated line |
{1:~ }| {1:~ }|
{4:search hit BOTTOM, continuing at TOP} | {4:search hit BOTTOM, continuing at TOP} |