mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(pum_redraw): use grid_puts_len() to truncate the text
Nvim already resizes grid to the required width, so there is no need to truncate the text in pum_redraw(). What's more, truncation is currently done incorrectly because Vim patch 8.2.1995 was ported incorrectly. This nearly reverts the truncation part of Vim patch 8.2.1995, but not the part that reduces unnecessary calls to pum_redraw(). The original PR https://github.com/vim/vim/pull/7306 didn't explain much about which part of it actually reduces redraws.
This commit is contained in:
parent
28dadd5a54
commit
e6d35b9e40
@ -542,17 +542,8 @@ void pum_redraw(void)
|
||||
xfree(st);
|
||||
col -= width;
|
||||
} else {
|
||||
int size = (int)STRLEN(st);
|
||||
int cells = (int)mb_string2cells(st);
|
||||
|
||||
// only draw the text that fits
|
||||
while (size > 0 && col + cells > pum_width + pum_col) {
|
||||
size--;
|
||||
size -= utf_head_off(st, st + size);
|
||||
cells -= utf_ptr2cells(st + size);
|
||||
}
|
||||
|
||||
grid_puts_len(&pum_grid, st, size, row, col, attr);
|
||||
// use grid_puts_len() to truncate the text
|
||||
grid_puts(&pum_grid, st, row, col, attr);
|
||||
xfree(st);
|
||||
col += width;
|
||||
}
|
||||
|
@ -2213,4 +2213,134 @@ describe('builtin popupmenu', function()
|
||||
feed('<c-y>')
|
||||
assert_alive()
|
||||
end)
|
||||
|
||||
it('truncates double-width character correctly when there is no scrollbar', function()
|
||||
screen:try_resize(32,8)
|
||||
command('set completeopt+=menuone,noselect')
|
||||
feed('i' .. string.rep(' ', 13))
|
||||
funcs.complete(14, {'哦哦哦哦哦哦哦哦哦哦'})
|
||||
screen:expect([[
|
||||
^ |
|
||||
{1:~ }{n: 哦哦哦哦哦哦哦哦哦>}|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- INSERT --} |
|
||||
]])
|
||||
end)
|
||||
|
||||
it('truncates double-width character correctly when there is scrollbar', function()
|
||||
screen:try_resize(32,8)
|
||||
command('set completeopt+=noselect')
|
||||
command('set pumheight=4')
|
||||
feed('i' .. string.rep(' ', 12))
|
||||
local items = {}
|
||||
for _ = 1, 8 do
|
||||
table.insert(items, {word = '哦哦哦哦哦哦哦哦哦哦', equal = 1, dup = 1})
|
||||
end
|
||||
funcs.complete(13, items)
|
||||
screen:expect([[
|
||||
^ |
|
||||
{1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
|
||||
{1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
|
||||
{1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
|
||||
{1:~ }{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{2:-- INSERT --} |
|
||||
]])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('builtin popupmenu with ui/ext_multigrid', function()
|
||||
local screen
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new(32, 20)
|
||||
screen:attach({ext_multigrid=true})
|
||||
screen:set_default_attr_ids({
|
||||
-- popup selected item / scrollbar track
|
||||
['s'] = {background = Screen.colors.WebGray},
|
||||
-- popup non-selected item
|
||||
['n'] = {background = Screen.colors.LightMagenta},
|
||||
-- popup scrollbar knob
|
||||
['c'] = {background = Screen.colors.Grey0},
|
||||
[1] = {bold = true, foreground = Screen.colors.Blue},
|
||||
[2] = {bold = true},
|
||||
[3] = {reverse = true},
|
||||
[4] = {bold = true, reverse = true},
|
||||
[5] = {bold = true, foreground = Screen.colors.SeaGreen},
|
||||
[6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
|
||||
})
|
||||
end)
|
||||
|
||||
it('truncates double-width character correctly when there is no scrollbar', function()
|
||||
screen:try_resize(32,8)
|
||||
command('set completeopt+=menuone,noselect')
|
||||
feed('i' .. string.rep(' ', 13))
|
||||
funcs.complete(14, {'哦哦哦哦哦哦哦哦哦哦'})
|
||||
screen:expect({grid=[[
|
||||
## grid 1
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[3:--------------------------------]|
|
||||
## grid 2
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
## grid 3
|
||||
{2:-- INSERT --} |
|
||||
## grid 4
|
||||
{n: 哦哦哦哦哦哦哦哦哦>}|
|
||||
]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 12, false, 100}}})
|
||||
end)
|
||||
|
||||
it('truncates double-width character correctly when there is scrollbar', function()
|
||||
screen:try_resize(32,8)
|
||||
command('set completeopt+=noselect')
|
||||
command('set pumheight=4')
|
||||
feed('i' .. string.rep(' ', 12))
|
||||
local items = {}
|
||||
for _ = 1, 8 do
|
||||
table.insert(items, {word = '哦哦哦哦哦哦哦哦哦哦', equal = 1, dup = 1})
|
||||
end
|
||||
funcs.complete(13, items)
|
||||
screen:expect({grid=[[
|
||||
## grid 1
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[2:--------------------------------]|
|
||||
[3:--------------------------------]|
|
||||
## grid 2
|
||||
^ |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
## grid 3
|
||||
{2:-- INSERT --} |
|
||||
## grid 4
|
||||
{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
|
||||
{n: 哦哦哦哦哦哦哦哦哦>}{c: }|
|
||||
{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
|
||||
{n: 哦哦哦哦哦哦哦哦哦>}{s: }|
|
||||
]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 11, false, 100}}})
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user