From a9418ef8cfc00943fcd6f8f2236783442e09e91b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 24 Aug 2023 11:28:10 +0800 Subject: [PATCH] fix(ui): wrong display with 0-width inline virt_text at eol (#24854) --- src/nvim/drawline.c | 7 +++++-- test/functional/ui/decorations_spec.lua | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index fa2aecff86..3638ea19f4 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -877,7 +877,8 @@ static bool has_more_inline_virt(winlinevars_T *wlv, ptrdiff_t v) DecorRange *item = &kv_A(state->active, i); if (item->start_row != state->row || !kv_size(item->decor.virt_text) - || item->decor.virt_text_pos != kVTInline) { + || item->decor.virt_text_pos != kVTInline + || item->decor.virt_text_width == 0) { continue; } if (item->draw_col >= -1 && item->start_col >= v) { @@ -899,7 +900,8 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t DecorRange *item = &kv_A(state->active, i); if (item->start_row != state->row || !kv_size(item->decor.virt_text) - || item->decor.virt_text_pos != kVTInline) { + || item->decor.virt_text_pos != kVTInline + || item->decor.virt_text_width == 0) { continue; } if (item->draw_col >= -1 && item->start_col == v) { @@ -935,6 +937,7 @@ static void handle_inline_virtual_text(win_T *wp, winlinevars_T *wlv, ptrdiff_t // If the text didn't reach until the first window // column we need to skip cells. if (wlv->skip_cells > 0) { + // FIXME: this should use virt_text_width instead int virt_text_len = wlv->n_attr; if (virt_text_len > wlv->skip_cells) { int len = mb_charlen2bytelen(wlv->p_extra, wlv->skip_cells); diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 6c1a7a6a2c..0a3a2e4e29 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -1748,7 +1748,7 @@ describe('decorations: inline virtual text', function() ]]} end) - it('works with empty chunk', function() + it('works with 0-width chunk', function() screen:try_resize(50, 10) insert(example_text) feed 'gg' @@ -1766,7 +1766,22 @@ describe('decorations: inline virtual text', function() ]]} meths.buf_set_extmark(0, ns, 0, 5, {virt_text={{''}, {''}}, virt_text_pos='inline'}) - meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {': ', 'Special'}, {'string', 'Type'}}, virt_text_pos='inline'}) + meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {': ', 'Special'}}, virt_text_pos='inline'}) + meths.buf_set_extmark(0, ns, 1, 48, {virt_text={{''}, {''}}, virt_text_pos='inline'}) + screen:expect{grid=[[ + ^for _,item in ipairs(items) do | + local text{10:: }, hl_id_cell, count = unpack(item)| + if hl_id_cell ~= nil then | + hl_id = hl_id_cell | + end | + for _ = 1, (count or 1) do | + local cell = line[colpos] | + cell.text = text | + cell.hl_id = hl_id | + | + ]]} + + meths.buf_set_extmark(0, ns, 1, 14, {virt_text={{''}, {'string', 'Type'}}, virt_text_pos='inline'}) feed('V') screen:expect{grid=[[ ^f{7:or _,item in ipairs(items) do} |