mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
feat(extmarks): support hl_mode "combine" for inline virt_text (#24099)
This commit is contained in:
parent
134b9ec483
commit
f0884f21fa
@ -2630,9 +2630,10 @@ nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {*opts})
|
||||
highlights of the text. Currently only affects virt_text
|
||||
highlights, but might affect `hl_group` in later versions.
|
||||
• "replace": only show the virt_text color. This is the
|
||||
default
|
||||
• "combine": combine with background text color
|
||||
• "blend": blend with background text color.
|
||||
default.
|
||||
• "combine": combine with background text color.
|
||||
• "blend": blend with background text color. Not supported
|
||||
for "inline" virt_text.
|
||||
|
||||
• virt_lines : virtual lines to add next to this mark This
|
||||
should be an array over lines, where each line in turn is
|
||||
|
@ -490,10 +490,10 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
|
||||
/// highlights of the text. Currently only affects
|
||||
/// virt_text highlights, but might affect `hl_group`
|
||||
/// in later versions.
|
||||
/// - "replace": only show the virt_text color. This is the
|
||||
/// default
|
||||
/// - "combine": combine with background text color
|
||||
/// - "replace": only show the virt_text color. This is the default.
|
||||
/// - "combine": combine with background text color.
|
||||
/// - "blend": blend with background text color.
|
||||
/// Not supported for "inline" virt_text.
|
||||
///
|
||||
/// - virt_lines : virtual lines to add next to this mark
|
||||
/// This should be an array over lines, where each line in
|
||||
@ -730,6 +730,11 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
} else if (strequal("combine", str.data)) {
|
||||
decor.hl_mode = kHlModeCombine;
|
||||
} else if (strequal("blend", str.data)) {
|
||||
if (decor.virt_text_pos == kVTInline) {
|
||||
VALIDATE(false, "%s", "cannot use 'blend' hl_mode with inline virtual text", {
|
||||
goto error;
|
||||
});
|
||||
}
|
||||
decor.hl_mode = kHlModeBlend;
|
||||
} else {
|
||||
VALIDATE_S(false, "hl_mode", str.data, {
|
||||
|
@ -128,6 +128,7 @@ typedef struct {
|
||||
|
||||
VirtText virt_inline;
|
||||
size_t virt_inline_i;
|
||||
HlMode virt_inline_hl_mode;
|
||||
|
||||
bool reset_extra_attr;
|
||||
|
||||
@ -886,6 +887,7 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t
|
||||
}
|
||||
if (item->draw_col >= -1 && item->start_col == v) {
|
||||
wlv->virt_inline = item->decor.virt_text;
|
||||
wlv->virt_inline_hl_mode = item->decor.hl_mode;
|
||||
item->draw_col = INT_MIN;
|
||||
break;
|
||||
}
|
||||
@ -1798,7 +1800,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
|
||||
|
||||
if (!has_fold) {
|
||||
handle_inline_virtual_text(wp, &wlv, v);
|
||||
if (wlv.n_extra > 0) {
|
||||
if (wlv.n_extra > 0 && wlv.virt_inline_hl_mode <= kHlModeReplace) {
|
||||
// restore search_attr and area_attr when n_extra is down to zero
|
||||
// TODO(bfredl): this is ugly as fuck. look if we can do this some other way.
|
||||
saved_search_attr = search_attr;
|
||||
|
@ -1587,13 +1587,15 @@ describe('decorations: inline virtual text', function()
|
||||
[9] = {background = Screen.colors.Plum1};
|
||||
[10] = {foreground = Screen.colors.SlateBlue};
|
||||
[11] = {blend = 30, background = Screen.colors.Red1};
|
||||
[12] = {background = Screen.colors.Yellow1};
|
||||
[12] = {background = Screen.colors.Yellow};
|
||||
[13] = {reverse = true};
|
||||
[14] = {foreground = Screen.colors.SlateBlue, background = Screen.colors.LightMagenta};
|
||||
[15] = {bold = true, reverse = true};
|
||||
[16] = {foreground = Screen.colors.Red};
|
||||
[17] = {background = Screen.colors.LightGrey, foreground = Screen.colors.DarkBlue};
|
||||
[18] = {background = Screen.colors.LightGrey, foreground = Screen.colors.Red};
|
||||
[19] = {background = Screen.colors.Yellow, foreground = Screen.colors.SlateBlue};
|
||||
[20] = {background = Screen.colors.LightGrey, foreground = Screen.colors.SlateBlue};
|
||||
}
|
||||
|
||||
ns = meths.create_namespace 'test'
|
||||
@ -2000,13 +2002,15 @@ bbbbbbb]])
|
||||
end)
|
||||
|
||||
it('search highlight is correct', function()
|
||||
insert('foo foo foo foo')
|
||||
feed('0')
|
||||
meths.buf_set_extmark(0, ns, 0, 8,
|
||||
{ virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
|
||||
insert('foo foo foo foo\nfoo foo foo foo')
|
||||
feed('gg0')
|
||||
meths.buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' })
|
||||
meths.buf_set_extmark(0, ns, 0, 9, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
|
||||
meths.buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
|
||||
meths.buf_set_extmark(0, ns, 1, 9, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
|
||||
screen:expect { grid = [[
|
||||
^foo foo {10:virtual text}foo foo |
|
||||
{1:~ }|
|
||||
^foo foo f{10:AAABBB}oo foo |
|
||||
foo foo f{10:CCCDDD}oo foo |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -2019,8 +2023,8 @@ bbbbbbb]])
|
||||
|
||||
feed('/foo')
|
||||
screen:expect { grid = [[
|
||||
{12:foo} {13:foo} {10:virtual text}{12:foo} {12:foo} |
|
||||
{1:~ }|
|
||||
{12:foo} {13:foo} {12:f}{10:AAA}{19:BBB}{12:oo} {12:foo} |
|
||||
{12:foo} {12:foo} {12:f}{19:CCC}{10:DDD}{12:oo} {12:foo} |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -2033,14 +2037,16 @@ bbbbbbb]])
|
||||
end)
|
||||
|
||||
it('visual select highlight is correct', function()
|
||||
insert('foo foo foo foo')
|
||||
feed('0')
|
||||
meths.buf_set_extmark(0, ns, 0, 8,
|
||||
{ virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
|
||||
insert('foo foo foo foo\nfoo foo foo foo')
|
||||
feed('gg0')
|
||||
meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'AAA', 'Special' } }, virt_text_pos = 'inline' })
|
||||
meths.buf_set_extmark(0, ns, 0, 8, { virt_text = { { 'BBB', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
|
||||
meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'CCC', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'combine' })
|
||||
meths.buf_set_extmark(0, ns, 1, 8, { virt_text = { { 'DDD', 'Special' } }, virt_text_pos = 'inline', hl_mode = 'replace' })
|
||||
feed('8l')
|
||||
screen:expect { grid = [[
|
||||
foo foo {10:virtual text}^foo foo |
|
||||
{1:~ }|
|
||||
foo foo {10:AAABBB}^foo foo |
|
||||
foo foo {10:CCCDDD}foo foo |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -2051,10 +2057,11 @@ bbbbbbb]])
|
||||
|
|
||||
]]}
|
||||
|
||||
feed('v')
|
||||
feed('2h')
|
||||
feed('<C-V>')
|
||||
feed('2hj')
|
||||
screen:expect { grid = [[
|
||||
foo fo^o{7: }{10:virtual text}{7:f}oo foo |
|
||||
foo fo{7:o }{10:AAA}{20:BBB}{7:f}oo foo |
|
||||
foo fo^o{7: }{20:CCC}{10:DDD}{7:f}oo foo |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -2062,8 +2069,7 @@ bbbbbbb]])
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{8:-- VISUAL --} |
|
||||
{8:-- VISUAL BLOCK --} |
|
||||
]]}
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user