fix(extmarks): empty inline virt_text interfering with DiffText (#24101)

This commit is contained in:
zeertzjq 2023-06-22 17:48:53 +08:00 committed by GitHub
parent 130b8c801a
commit 958cc22836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 7 deletions

View File

@ -897,14 +897,16 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t
} else {
// already inside existing inline virtual text with multiple chunks
VirtTextChunk vtc = kv_A(wlv->virt_inline, wlv->virt_inline_i);
wlv->virt_inline_i++;
wlv->p_extra = vtc.text;
wlv->n_extra = (int)strlen(wlv->p_extra);
wlv->extra_for_extmark = true;
wlv->n_extra = (int)strlen(vtc.text);
if (wlv->n_extra == 0) {
continue;
}
wlv->c_extra = NUL;
wlv->c_final = NUL;
wlv->extra_attr = vtc.hl_id ? syn_id2attr(vtc.hl_id) : 0;
wlv->n_attr = mb_charlen(vtc.text);
wlv->virt_inline_i++;
// If the text didn't reach until the first window
// column we need to skip cells.
if (wlv->skip_cells > 0) {
@ -925,11 +927,12 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t
wlv->skipped_cells += virt_text_len;
wlv->n_attr = 0;
wlv->n_extra = 0;
// go to the start so the next virtual text chunk can be selected.
continue;
}
}
assert(wlv->n_extra > 0);
wlv->extra_for_extmark = true;
}
}
}

View File

@ -2216,6 +2216,51 @@ bbbbbbb]])
]]}
end)
it('hidden virtual text does not interfere with Visual highlight', function()
insert('abcdef')
command('set nowrap')
meths.buf_set_extmark(0, ns, 0, 0, { virt_text = { { 'XXX', 'Special' } }, virt_text_pos = 'inline' })
feed('V2zl')
screen:expect{grid=[[
{10:X}{7:abcde}^f |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{8:-- VISUAL LINE --} |
]]}
feed('zl')
screen:expect{grid=[[
{7:abcde}^f |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{8:-- VISUAL LINE --} |
]]}
feed('zl')
screen:expect{grid=[[
{7:bcde}^f |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{8:-- VISUAL LINE --} |
]]}
end)
it('highlighting is correct when virtual text wraps with number', function()
insert([[
test
@ -2279,9 +2324,11 @@ bbbbbbb]])
9000
0009
]])
insert('aaa\tbbb')
command("set diff")
meths.buf_set_extmark(0, ns, 0, 1,
{ virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
meths.buf_set_extmark(0, ns, 0, 1, { virt_text = { { 'test', 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
meths.buf_set_extmark(0, ns, 5, 0, { virt_text = { { '!', 'Special' } }, virt_text_pos = 'inline' })
meths.buf_set_extmark(0, ns, 5, 3, { virt_text = { { '' } }, virt_text_pos = 'inline' })
command("vnew")
insert([[
000
@ -2290,6 +2337,7 @@ bbbbbbb]])
000
000
]])
insert('aaabbb')
command("set diff")
feed('gg0')
screen:expect { grid = [[
@ -2298,12 +2346,26 @@ bbbbbbb]])
{9:000 }{9:000}{5:9}{9: }|
{9:000 }{5:9}{9:000 }|
{9:000 }{9:000}{5:9}{9: }|
|
{9:aaabbb }{14:!}{9:aaa}{5: }{9:bbb }|
{1:~ }{1:~ }|
{1:~ }{1:~ }|
{15:[No Name] [+] }{13:[No Name] [+] }|
|
]]}
command('wincmd w | set nowrap')
feed('zl')
screen:expect { grid = [[
{9:000 }{14:test}{9:000 }|
{9:000 }{9:00}{5:9}{9: }|
{9:000 }{9:00}{5:9}{9: }|
{9:000 }{9:000 }|
{9:000 }{9:00}{5:9}{9: }|
{9:aaabbb }{9:aaa}{5: }{9:bb^b }|
{1:~ }{1:~ }|
{1:~ }{1:~ }|
{13:[No Name] [+] }{15:[No Name] [+] }|
|
]]}
end)
it('correctly draws when there are multiple overlapping virtual texts on the same line with nowrap', function()