fix(charset): fix wrong display of 0xffff (#24158)

This commit is contained in:
zeertzjq 2023-06-26 11:52:52 +08:00 committed by GitHub
parent 91aeaeef64
commit cd6458123f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -645,8 +645,8 @@ size_t transchar_hex(char *const buf, const int c)
size_t i = 0; size_t i = 0;
buf[i++] = '<'; buf[i++] = '<';
if (c > 255) { if (c > 0xFF) {
if (c > 255 * 256) { if (c > 0xFFFF) {
buf[i++] = (char)nr2hex((unsigned)c >> 20); buf[i++] = (char)nr2hex((unsigned)c >> 20);
buf[i++] = (char)nr2hex((unsigned)c >> 16); buf[i++] = (char)nr2hex((unsigned)c >> 16);
} }

View File

@ -17,10 +17,11 @@ describe("multibyte rendering", function()
screen = Screen.new(60, 6) screen = Screen.new(60, 6)
screen:attach({rgb=true}) screen:attach({rgb=true})
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue1}, [1] = {bold = true, foreground = Screen.colors.Blue},
[2] = {background = Screen.colors.WebGray}, [2] = {background = Screen.colors.WebGray},
[3] = {background = Screen.colors.LightMagenta}, [3] = {background = Screen.colors.LightMagenta},
[4] = {bold = true}, [4] = {bold = true},
[5] = {foreground = Screen.colors.Blue},
}) })
end) end)
@ -119,6 +120,19 @@ describe("multibyte rendering", function()
]]) ]])
end) end)
it('0xffff is shown as 4 hex digits', function()
command([[call setline(1, "\uFFFF!!!")]])
feed('$')
screen:expect{grid=[[
{5:<ffff>}!!^! |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
|
]]}
end)
it('works with a lot of unicode (zalgo) text', function() it('works with a lot of unicode (zalgo) text', function()
screen:try_resize(65, 10) screen:try_resize(65, 10)
meths.buf_set_lines(0,0,-1,true, split(dedent [[ meths.buf_set_lines(0,0,-1,true, split(dedent [[