Skip to content

Commit

Permalink
feat(api): relax statusline fillchar width check
Browse files Browse the repository at this point in the history
Treat fillchar as single-width even if it isn't.
  • Loading branch information
zeertzjq committed Mar 9, 2022
1 parent a978d76 commit 3011794
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/nvim/api/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err)
/// - winid: (number) |window-ID| of the window to use as context for statusline.
/// - maxwidth: (number) Maximum width of statusline.
/// - fillchar: (string) Character to fill blank spaces in the statusline (see
/// 'fillchars').
/// 'fillchars'). Treated as single-width even if it isn't.
/// - highlights: (boolean) Return highlight information.
/// - use_tabline: (boolean) Evaluate tabline instead of statusline. When |TRUE|, {winid}
/// is ignored.
Expand Down Expand Up @@ -2277,11 +2277,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *

if (HAS_KEY(opts->fillchar)) {
if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0
|| char2cells(fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data)) != 1
|| (size_t)utf_char2len(fillchar) != opts->fillchar.data.string.size) {
api_set_error(err, kErrorTypeValidation, "fillchar must be a single-width character");
|| ((size_t)utf_ptr2len((char_u *)opts->fillchar.data.string.data)
!= opts->fillchar.data.string.size)) {
api_set_error(err, kErrorTypeValidation, "fillchar must be a single character");
return result;
}
fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data);
}

if (HAS_KEY(opts->highlights)) {
Expand Down
18 changes: 9 additions & 9 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2621,24 +2621,24 @@ describe('API', function()
eq({ str = 'a━━━b', width = 5 },
meths.eval_statusline('a%=b', { fillchar = '', maxwidth = 5 }))
end)
it('rejects double-width fillchar', function()
eq('fillchar must be a single-width character',
pcall_err(meths.eval_statusline, '', { fillchar = '' }))
it('treats double-width fillchar as single-width', function()
eq({ str = 'a哦哦哦b', width = 5 },
meths.eval_statusline('a%=b', { fillchar = '', maxwidth = 5 }))
end)
it('rejects control character fillchar', function()
eq('fillchar must be a single-width character',
pcall_err(meths.eval_statusline, '', { fillchar = '\a' }))
it('treats control character fillchar as single-width', function()
eq({ str = 'a\031\031\031b', width = 5 },
meths.eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 }))
end)
it('rejects multiple-character fillchar', function()
eq('fillchar must be a single-width character',
eq('fillchar must be a single character',
pcall_err(meths.eval_statusline, '', { fillchar = 'aa' }))
end)
it('rejects empty string fillchar', function()
eq('fillchar must be a single-width character',
eq('fillchar must be a single character',
pcall_err(meths.eval_statusline, '', { fillchar = '' }))
end)
it('rejects non-string fillchar', function()
eq('fillchar must be a single-width character',
eq('fillchar must be a single character',
pcall_err(meths.eval_statusline, '', { fillchar = 1 }))
end)
describe('highlight parsing', function()
Expand Down

0 comments on commit 3011794

Please sign in to comment.