mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #17666 from zeertzjq/api-statusline-fillchar-relax
feat(api): relax statusline fillchar width check
This commit is contained in:
commit
d6fe06b0a6
@ -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.
|
||||
@ -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)) {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user