mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
fix(ui): fix multi-byte characters highlight in virtual text
This also fixes insert cursor position around virtual text
vim-patch:9.0.0132: multi-byte characters in virtual text not handled correctly
Problem: Multi-byte characters in virtual text not handled correctly.
Solution: Count screen cells instead of bytes.
09ff4b54fb
This commit is contained in:
parent
389f5ca39d
commit
0c7fa3bdcc
@ -1079,8 +1079,10 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
|
||||
}
|
||||
|
||||
if (cursor != NULL) {
|
||||
// cursor is after inserted text
|
||||
vcol += cts.cts_cur_text_width;
|
||||
if ((State & MODE_INSERT) == 0) {
|
||||
// cursor is after inserted text
|
||||
vcol += cts.cts_cur_text_width;
|
||||
}
|
||||
if ((*ptr == TAB)
|
||||
&& (State & MODE_NORMAL)
|
||||
&& !wp->w_p_list
|
||||
|
@ -1824,7 +1824,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
|
||||
wlv.c_extra = NUL;
|
||||
wlv.c_final = NUL;
|
||||
wlv.extra_attr = vtc.hl_id ? syn_id2attr(vtc.hl_id) : 0;
|
||||
n_attr = wlv.n_extra;
|
||||
n_attr = mb_charlen(vtc.text);
|
||||
extmark_attr = 0;
|
||||
virt_inline_i++;
|
||||
}
|
||||
|
@ -1254,7 +1254,7 @@ end]]
|
||||
{ virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' })
|
||||
feed '^'
|
||||
feed '4l'
|
||||
screen:expect { grid = [[
|
||||
screen:expect { grid = [[
|
||||
1234{28: virtual text virtual text }^5678 |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -1274,12 +1274,12 @@ end]]
|
||||
end)
|
||||
|
||||
it('adjusts cursor location correctly when inserting around inline virtual text', function()
|
||||
insert('12345678')
|
||||
feed '$'
|
||||
meths.buf_set_extmark(0, ns, 0, 4,
|
||||
insert('12345678')
|
||||
feed '$'
|
||||
meths.buf_set_extmark(0, ns, 0, 4,
|
||||
{ virt_text = { { ' virtual text ', 'Special' } }, virt_text_pos = 'inline' })
|
||||
|
||||
screen:expect { grid = [[
|
||||
screen:expect { grid = [[
|
||||
1234{28: virtual text }567^8 |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
@ -1295,8 +1295,78 @@ end]]
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
|
||||
]]
|
||||
}
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('has correct highlighting with multi-byte characters in inline virtual text', function()
|
||||
insert('12345678')
|
||||
meths.buf_set_extmark(0, ns, 0, 4,
|
||||
{ virt_text = { { 'múlti-byté chñröcters 修补', 'Special' } }, virt_text_pos = 'inline' })
|
||||
|
||||
screen:expect { grid = [[
|
||||
1234{28:múlti-byté chñröcters 修补}567^8 |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('has correct cursor position when inserting around virtual text', function()
|
||||
insert('12345678')
|
||||
meths.buf_set_extmark(0, ns, 0, 4,
|
||||
{ virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
|
||||
feed '^'
|
||||
feed '3l'
|
||||
feed 'a'
|
||||
screen:expect { grid = [[
|
||||
1234{28:^virtual text}5678 |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{24:-- INSERT --} |
|
||||
]]}
|
||||
feed '<ESC>'
|
||||
feed '^'
|
||||
feed '4l'
|
||||
feed 'i'
|
||||
screen:expect { grid = [[
|
||||
1234{28:^virtual text}5678 |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{24:-- INSERT --} |
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user