rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.81k stars 903 forks source link

Incorrect cursor_range Calculation in Ime::Preedit #3967

Open mitoma opened 3 hours ago

mitoma commented 3 hours ago

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

Microsoft Windows [Version 10.0.22631.4317]

Winit version

In versions 0.28.1 and later

mitoma commented 3 hours ago

In my case, it is working as expected after applying this patch. https://github.com/mitoma/winit/commit/67bbf97408427d3ebecd3555b3b9729a22cdeae1