feat(mbyte): support extended grapheme clusters including more emoji

Use the grapheme break algorithm from utf8proc to support grapheme
clusters from recent unicode versions.

Handle variant selector VS16 turning some codepoints into double-width
emoji. This means we need to use ptr2cells rather than char2cells when
possible.
This commit is contained in:
bfredl
2024-08-08 10:42:08 +02:00
parent 4353996d0f
commit cfdf68a7ac
34 changed files with 657 additions and 221 deletions

View File

@@ -1435,6 +1435,28 @@ describe('API', function()
it('cannot handle NULs', function()
eq(0, api.nvim_strwidth('\0abc'))
end)
it('can handle emoji with variant selectors and ZWJ', function()
local selector = '❤️'
eq(2, fn.strchars(selector))
eq(1, fn.strcharlen(selector))
eq(2, api.nvim_strwidth(selector))
local no_selector = ''
eq(1, fn.strchars(no_selector))
eq(1, fn.strcharlen(no_selector))
eq(1, api.nvim_strwidth(no_selector))
local selector_zwj_selector = '🏳️‍⚧️'
eq(5, fn.strchars(selector_zwj_selector))
eq(1, fn.strcharlen(selector_zwj_selector))
eq(2, api.nvim_strwidth(selector_zwj_selector))
local emoji_zwj_emoji = '🧑‍🌾'
eq(3, fn.strchars(emoji_zwj_emoji))
eq(1, fn.strcharlen(emoji_zwj_emoji))
eq(2, api.nvim_strwidth(emoji_zwj_emoji))
end)
end)
describe('nvim_get_current_line, nvim_set_current_line', function()