mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
windows: fix incorrect cursor_range calculation in Ime::Preedit
The `text` is retrieved as UTF-8 while `attributes` are based on UTF-16, thus the offset was getting out of sync on some unicode payloads like surrogate pairs. Fixes #3967.
This commit is contained in:
@@ -257,3 +257,4 @@ changelog entry.
|
|||||||
- On macOS, fixed `VideoMode::refresh_rate_millihertz` for fractional refresh rates.
|
- On macOS, fixed `VideoMode::refresh_rate_millihertz` for fractional refresh rates.
|
||||||
- On macOS, store monitor handle to avoid panics after going in/out of sleep.
|
- On macOS, store monitor handle to avoid panics after going in/out of sleep.
|
||||||
- On macOS, allow certain invalid monitor handles and return `None` instead of panicking.
|
- On macOS, allow certain invalid monitor handles and return `None` instead of panicking.
|
||||||
|
- On Windows, fixed `Ime::Preedit` cursor offset calculation.
|
||||||
|
|||||||
@@ -34,8 +34,13 @@ impl ImeContext {
|
|||||||
let mut first = None;
|
let mut first = None;
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
let mut boundary_before_char = 0;
|
let mut boundary_before_char = 0;
|
||||||
|
let mut attr_idx = 0;
|
||||||
|
|
||||||
|
for chr in text.chars() {
|
||||||
|
let Some(attr) = attrs.get(attr_idx).copied() else {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
|
||||||
for (attr, chr) in attrs.into_iter().zip(text.chars()) {
|
|
||||||
let char_is_targeted =
|
let char_is_targeted =
|
||||||
attr as u32 == ATTR_TARGET_CONVERTED || attr as u32 == ATTR_TARGET_NOTCONVERTED;
|
attr as u32 == ATTR_TARGET_CONVERTED || attr as u32 == ATTR_TARGET_NOTCONVERTED;
|
||||||
|
|
||||||
@@ -46,6 +51,7 @@ impl ImeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boundary_before_char += chr.len_utf8();
|
boundary_before_char += chr.len_utf8();
|
||||||
|
attr_idx += chr.len_utf16();
|
||||||
}
|
}
|
||||||
|
|
||||||
if first.is_some() && last.is_none() {
|
if first.is_some() && last.is_none() {
|
||||||
|
|||||||
Reference in New Issue
Block a user