vim-patch:9.1.1922: Wrong virtcol('$') with virtual text at EOL (#36643)

Problem:  Wrong virtcol('$') with virtual text at EOL (rickhowe).
Solution: Also add 1 to end virtcol when there is virtual text.
          (zeertzjq)

fixes: vim/vim#18761
closes: vim/vim#18762

d434f6c2a5
This commit is contained in:
zeertzjq
2025-11-21 08:02:20 +08:00
committed by GitHub
parent a8b9660ca3
commit 1eec08d1a2
2 changed files with 14 additions and 2 deletions

View File

@@ -551,9 +551,10 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
} else {
while (true) {
char_size = charsize_regular(&csarg, ci.ptr, vcol, ci.chr.value);
// make sure we don't go past the end of the line
if (*ci.ptr == NUL) {
// if cursor is at NUL, it is treated like 1 cell char unless there is virtual text
char_size.width = MAX(1, csarg.cur_text_width_left + csarg.cur_text_width_right);
// NUL at end of line only takes one column unless there is virtual text
char_size.width = 1 + csarg.cur_text_width_left + csarg.cur_text_width_right;
on_NUL = true;
break;
}

View File

@@ -5872,6 +5872,17 @@ describe('decorations: inline virtual text', function()
|
]])
end)
it("virtcol('$') is correct with inline virt text at EOL", function()
insert(('1234567890\n'):rep(6))
for _, v in ipairs({ { 2, 'a' }, { 3, 'ab' }, { 4, 'abc' }, { 5, 'abcd' }, { 6, 'αβγ口' } }) do
local ln, tx = unpack(v)
local co = fn.col({ ln, '$' })
eq(11, fn.virtcol({ ln, '$' }))
api.nvim_buf_set_extmark(0, ns, ln - 1, co - 1, { virt_text = { { tx } }, virt_text_pos = 'inline' })
eq(11 + fn.strwidth(tx), fn.virtcol({ ln, '$' }))
end
end)
end)
describe('decorations: virtual lines', function()