aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/api.txt7
-rw-r--r--src/nvim/api/extmark.c13
-rw-r--r--src/nvim/drawline.c4
-rw-r--r--test/functional/ui/decorations_spec.lua46
4 files changed, 42 insertions, 28 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index bd8bce9737..8c79279361 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -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
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index d79cbf7508..a101e1bbf1 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -478,7 +478,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// shifting the underlying text.
/// - "right_align": display right aligned in the window.
/// - "inline": display at the specified column, and
-/// shift the buffer text to the right as needed
+/// shift the buffer text to the right as needed
/// - virt_text_win_col : position the virtual text at a fixed
/// window column (starting from the first
/// text column)
@@ -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, {
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 34d15d85c3..9728804ed7 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -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;
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
index 419a16e7b5..5de0106a8c 100644
--- a/test/functional/ui/decorations_spec.lua
+++ b/test/functional/ui/decorations_spec.lua
@@ -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,11 +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 |
- {1:~ }|
+ 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:~ }|
@@ -2063,7 +2069,7 @@ bbbbbbb]])
{1:~ }|
{1:~ }|
{1:~ }|
- {8:-- VISUAL --} |
+ {8:-- VISUAL BLOCK --} |
]]}
end)