fix(extmarks): fix win_col virt_text drawn on wrong screen line (#25264)

This commit is contained in:
zeertzjq 2023-09-20 21:48:12 +08:00 committed by GitHub
parent 877d04d0fb
commit 818d7f6daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 8 deletions

View File

@ -254,7 +254,7 @@ static void decor_add(DecorState *state, int start_row, int start_col, int end_r
DecorRange range = { start_row, start_col, end_row, end_col,
*decor, attr_id,
kv_size(decor->virt_text) && owned, -1, ns_id, mark_id };
kv_size(decor->virt_text) && owned, -10, ns_id, mark_id };
kv_pushp(state->active);
size_t index;
@ -268,10 +268,10 @@ static void decor_add(DecorState *state, int start_row, int start_col, int end_r
kv_A(state->active, index) = range;
}
/// Initialize the draw_col of a newly-added non-inline virtual text item.
/// Initialize the draw_col of a newly-added virtual text item.
static void decor_init_draw_col(int win_col, bool hidden, DecorRange *item)
{
if (win_col < 0) {
if (win_col < 0 && item->decor.virt_text_pos != kVTInline) {
item->draw_col = win_col;
} else if (item->decor.virt_text_pos == kVTOverlay) {
item->draw_col = (item->decor.virt_text_hide && hidden) ? INT_MIN : win_col;
@ -371,8 +371,7 @@ next_mark:
spell = item.decor.spell;
}
if (item.start_row == state->row && item.start_col <= col
&& decor_virt_pos(&item.decor) && item.draw_col == -1
&& item.decor.virt_text_pos != kVTInline) {
&& decor_virt_pos(&item.decor) && item.draw_col == -10) {
decor_init_draw_col(win_col, hidden, &item);
}
if (keep) {

View File

@ -85,6 +85,7 @@ typedef struct {
/// Screen column to draw the virtual text.
/// When -1, the virtual text may be drawn after deciding where.
/// When -3, the virtual text should be drawn on the next screen line.
/// When -10, the virtual text has just been added.
/// When INT_MIN, the virtual text should no longer be drawn.
int draw_col;
uint64_t ns_id;

View File

@ -1237,6 +1237,25 @@ describe('extmark decorations', function()
|
]]}
meths.buf_set_extmark(0, ns, 4, 50, { virt_text={{'EOL', 'NonText'}} })
screen:expect{grid=[[
for _,item in ipairs(items) do |
local text, hl_id_cell, cou{4:Very} unpack(ite{4:VERY}|
if |
hl_id_cell ~= nil then {4:Much} {4:MUCH}|
--^ -- -- -- -- -- -- --{4:Error}- -- hl_i{4:ERROR}|
l_id_cell {1:EOL} |
end |
for _ = 1, (count or 1) do |
local cell = line[colpos] |
{1:-} cell.text = text {1:-}|
cell.hl_id = hl_id |
colpos = colpos+1 |
end |
end |
|
]]}
feed '.'
screen:expect{grid=[[
for _,item in ipairs(items) do |
@ -1244,7 +1263,7 @@ describe('extmark decorations', function()
if |
hl_id_cell ~= nil then {4:Much} {4:MUCH}|
--^ -- -- -- -- -- -- -- -- -- -- -- hl_id |
= hl_id_cell {4:Error} {4:ERROR}|
= hl_id_cell {1:EOL} {4:Error} {4:ERROR}|
end |
for _ = 1, (count or 1) do |
local cell = line[colpos] |
@ -1264,7 +1283,7 @@ describe('extmark decorations', function()
{2: 3 } if |
{2: 4 }hl_id_cell ~= nil then {4:Much} {4:MUCH}|
{2: 5 } --^ -- -- -- -- -- -- -- -- -- -- -- hl|
{2: }_id = hl_id_cell {4:Error} {4:ERROR}|
{2: }_id = hl_id_cell {1:EOL} {4:Error} {4:ERROR}|
{2: 6 } end |
{2: 7 } for _ = 1, (count or 1) do |
{2: 8 } local cell = line[colpos] |
@ -1283,7 +1302,7 @@ describe('extmark decorations', function()
{2: 3 } if |
{2: 4 }hl_id_cell ~= nil then {4:Much} {4:MUCH}|
{2: 5 } --^ -- -- -- -- -- -- -- -- -- -- -- hl|
_id = hl_id_cell {4:Error} {4:ERROR}|
_id = hl_id_cell {1:EOL} {4:Error} {4:ERROR}|
{2: 6 } end |
{2: 7 } for _ = 1, (count or 1) do |
{2: 8 } local cell = line[colpos] |