From 15e077fa4b542490ee28820baf651f48ce122549 Mon Sep 17 00:00:00 2001 From: moko256 Date: Sat, 16 Apr 2022 03:09:05 +0900 Subject: [PATCH] Win32: fix window commits last char when deleting text with IME (flutter/engine#32565) --- .../shell/platform/windows/window_win32.cc | 5 +++++ .../platform/windows/window_win32_unittests.cc | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/engine/src/flutter/shell/platform/windows/window_win32.cc b/engine/src/flutter/shell/platform/windows/window_win32.cc index aad1c1e17b..d3a8ecf134 100644 --- a/engine/src/flutter/shell/platform/windows/window_win32.cc +++ b/engine/src/flutter/shell/platform/windows/window_win32.cc @@ -212,6 +212,11 @@ void WindowWin32::OnImeComposition(UINT const message, // Update the IME window position. text_input_manager_->UpdateImeWindow(); + if (lparam == 0) { + OnComposeChange(u"", 0); + OnComposeCommit(); + } + if (lparam & GCS_COMPSTR) { // Read the in-progress composing string. long pos = text_input_manager_->GetComposingCursorPosition(); diff --git a/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc b/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc index eee9987901..fe16edd77d 100644 --- a/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc @@ -115,6 +115,23 @@ TEST(MockWin32Window, OnImeCompositionComposeAndResult) { GCS_COMPSTR | GCS_RESULTSTR); } +TEST(MockWin32Window, OnImeCompositionClearChange) { + MockTextInputManagerWin32* text_input_manager = + new MockTextInputManagerWin32(); + std::unique_ptr text_input_manager_ptr( + text_input_manager); + MockWin32Window window(std::move(text_input_manager_ptr)); + EXPECT_CALL(window, OnComposeChange(std::u16string(u""), 0)).Times(1); + EXPECT_CALL(window, OnComposeCommit()).Times(1); + ON_CALL(window, OnImeComposition) + .WillByDefault(Invoke(&window, &MockWin32Window::CallOnImeComposition)); + EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1); + + // send an IME_COMPOSITION event that contains both the result string and the + // composition string. + window.InjectWindowMessage(WM_IME_COMPOSITION, 0, 0); +} + TEST(MockWin32Window, HorizontalScroll) { MockWin32Window window; const int scroll_amount = 10;