windows: Fix Japanese IME (#32153)

张小白 created

Fixed an issue where pressing `Escape` wouldn’t clear all pre-edit text
when using Japanese IME.


Release Notes:

- N/A

Change summary

crates/gpui/src/platform/windows/events.rs | 8 ++++++++
1 file changed, 8 insertions(+)

Detailed changes

crates/gpui/src/platform/windows/events.rs 🔗

@@ -679,6 +679,14 @@ fn handle_ime_composition_inner(
     lparam: LPARAM,
     state_ptr: Rc<WindowsWindowStatePtr>,
 ) -> Option<isize> {
+    if lparam.0 == 0 {
+        // Japanese IME may send this message with lparam = 0, which indicates that
+        // there is no composition string.
+        with_input_handler(&state_ptr, |input_handler| {
+            input_handler.replace_text_in_range(None, "");
+        })?;
+        return Some(0);
+    }
     let mut ime_input = None;
     if lparam.0 as u32 & GCS_COMPSTR.0 > 0 {
         let comp_string = parse_ime_compostion_string(ctx)?;