1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Fix: problems pointed out by Copilot

https://github.com/emilk/egui/pull/8083#pullrequestreview-4364725473
This commit is contained in:
umajho
2026-05-27 07:22:13 +08:00
parent b1335f6c44
commit c8439f3150
4 changed files with 44 additions and 18 deletions

View File

@@ -689,16 +689,25 @@ impl State {
// See <https://github.com/rust-windowing/winit/issues/2498>
winit::event::Ime::Enabled | winit::event::Ime::Disabled => {}
winit::event::Ime::Preedit(text, active_range_bytes) => {
let active_range_chars = match active_range_bytes.clone() {
Some((start_bytes, end_bytes)) => {
let (Some(start_chars), Some(middle_chars)) = (
text.get(..start_bytes).map(|s| s.chars().count()),
text.get(start_bytes..end_bytes).map(|s| s.chars().count()),
) else {
log::warn!("{ime:?} is ignored due to invalid range");
return;
};
Some(start_chars..start_chars + middle_chars)
}
None => None,
};
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Preedit {
text: text.clone(),
active_range_chars: active_range_bytes.map(|(start_bytes, end_bytes)| {
let start_char = text[..start_bytes].chars().count();
let end_char =
start_char + text[start_bytes..end_bytes].chars().count();
start_char..end_char
}),
active_range_chars,
}));
}
winit::event::Ime::Commit(text) => {