When using the Japanese IME (Microsoft IME) with winit, the cursor_range value in Ime::Preedit(text, cursor_range) becomes corrupted.
For example, when trying to convert the string “ぶたがなく” within the range of “ぶたが”, the cursor_range should ideally be "(start)🐖が(end)なく". However, it ends up being "(start)🐖がな(end)く", with the (end) position being off by one character.
This issue arises because the character “🐖” is passed as a UTF-16 surrogate pair in Windows. Although the cursor position attribute is also based on UTF-16, winit’s calculation of cursor_range does not account for surrogate pairs.
Please update the cursor_range calculation to handle surrogate pairs correctly.
Description
When using the Japanese IME (Microsoft IME) with winit, the cursor_range value in Ime::Preedit(text, cursor_range) becomes corrupted.
For example, when trying to convert the string “ぶたがなく” within the range of “ぶたが”, the cursor_range should ideally be "(start)🐖が(end)なく". However, it ends up being "(start)🐖がな(end)く", with the (end) position being off by one character.
This issue arises because the character “🐖” is passed as a UTF-16 surrogate pair in Windows. Although the cursor position attribute is also based on UTF-16, winit’s calculation of cursor_range does not account for surrogate pairs.
Please update the cursor_range calculation to handle surrogate pairs correctly.
Windows version
Winit version
In versions 0.28.1 and later