fix(statusline): fill for double-width char after moving items (#24207)

This commit is contained in:
zeertzjq 2023-06-30 08:36:09 +08:00 committed by GitHub
parent 8758c6fb87
commit d7bb19e013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 23 deletions

View File

@ -263,6 +263,7 @@ void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_r
};
for (int i = 0; click_recs[i].start != NULL; i++) {
len += vim_strnsize(buf, (int)(click_recs[i].start - buf));
assert(len <= width);
if (col < len) {
while (col < len) {
click_defs[col++] = cur_click_def;
@ -2052,17 +2053,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
// Put a `<` to mark where we truncated at
*trunc_p = '<';
if (width + 1 < maxwidth) {
// Advance the pointer to the end of the string
trunc_p = trunc_p + strlen(trunc_p);
}
// Fill up for half a double-wide character.
while (++width < maxwidth) {
MB_CHAR2BYTES(fillchar, trunc_p);
*trunc_p = NUL;
}
// }
// { Change the start point for items based on
@ -2084,6 +2074,17 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
}
}
// }
if (width + 1 < maxwidth) {
// Advance the pointer to the end of the string
trunc_p = trunc_p + strlen(trunc_p);
}
// Fill up for half a double-wide character.
while (++width < maxwidth) {
MB_CHAR2BYTES(fillchar, trunc_p);
*trunc_p = NUL;
}
}
width = maxwidth;

View File

@ -1,6 +1,9 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, command, eq = helpers.clear, helpers.command, helpers.eq
local insert = helpers.insert
local meths = helpers.meths
local assert_alive = helpers.assert_alive
describe('ui/ext_tabline', function()
local screen
@ -92,6 +95,10 @@ describe("tabline", function()
clear()
screen = Screen.new(42, 5)
screen:attach()
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue}; -- NonText
[1] = {reverse = true}; -- TabLineFill
})
end)
it('redraws when tabline option is set', function()
@ -100,24 +107,18 @@ describe("tabline", function()
screen:expect{grid=[[
{1:asdf }|
^ |
{2:~ }|
{2:~ }|
{0:~ }|
{0:~ }|
|
]], attr_ids={
[1] = {reverse = true};
[2] = {bold = true, foreground = Screen.colors.Blue1};
}}
]]}
command('set tabline=jkl')
screen:expect{grid=[[
{1:jkl }|
^ |
{2:~ }|
{2:~ }|
{0:~ }|
{0:~ }|
|
]], attr_ids={
[1] = {reverse = true};
[2] = {bold = true, foreground = Screen.colors.Blue};
}}
]]}
end)
it('click definitions do not leak memory #21765', function()
@ -125,4 +126,52 @@ describe("tabline", function()
command('set showtabline=2')
command('redrawtabline')
end)
it('clicks work with truncated double-width label #24187', function()
insert('tab1')
command('tabnew')
insert('tab2')
command('tabprev')
meths.set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {})
screen:expect{grid=[[
{1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
tab^1 |
{0:~ }|
{0:~ }|
|
]]}
assert_alive()
meths.input_mouse('left', 'press', '', 0, 0, 1)
screen:expect{grid=[[
{1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
tab^2 |
{0:~ }|
{0:~ }|
|
]]}
meths.input_mouse('left', 'press', '', 0, 0, 0)
screen:expect{grid=[[
{1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
tab^1 |
{0:~ }|
{0:~ }|
|
]]}
meths.input_mouse('left', 'press', '', 0, 0, 39)
screen:expect{grid=[[
{1:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
tab^2 |
{0:~ }|
{0:~ }|
|
]]}
meths.input_mouse('left', 'press', '', 0, 0, 40)
screen:expect{grid=[[
tab^1 |
{0:~ }|
{0:~ }|
{0:~ }|
|
]]}
end)
end)