diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 41db04952e5..3d8e9184fdc 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -99,6 +99,7 @@ pub struct State { accesskit: Option, allow_ime: bool, + ime_rect_px: Option, } impl State { @@ -139,6 +140,7 @@ impl State { accesskit: None, allow_ime: false, + ime_rect_px: None, }; slf.egui_input @@ -817,19 +819,26 @@ impl State { } if let Some(ime) = ime { - let rect = ime.rect; let pixels_per_point = pixels_per_point(&self.egui_ctx, window); - crate::profile_scope!("set_ime_cursor_area"); - window.set_ime_cursor_area( - winit::dpi::PhysicalPosition { - x: pixels_per_point * rect.min.x, - y: pixels_per_point * rect.min.y, - }, - winit::dpi::PhysicalSize { - width: pixels_per_point * rect.width(), - height: pixels_per_point * rect.height(), - }, - ); + let ime_rect_px = pixels_per_point * ime.rect; + if self.ime_rect_px != Some(ime_rect_px) + || self.egui_ctx.input(|i| !i.events.is_empty()) + { + self.ime_rect_px = Some(ime_rect_px); + crate::profile_scope!("set_ime_cursor_area"); + window.set_ime_cursor_area( + winit::dpi::PhysicalPosition { + x: ime_rect_px.min.x, + y: ime_rect_px.min.y, + }, + winit::dpi::PhysicalSize { + width: ime_rect_px.width(), + height: ime_rect_px.height(), + }, + ); + } + } else { + self.ime_rect_px = None; } #[cfg(feature = "accesskit")]