Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2fa5ce4

Browse files
authored
[Windows] Google Japanese Input, composing text doesn't rendered after commit text partially (#33605)
Reproducible steps is in flutter/flutter#102021. Fixes flutter/flutter#102021. No changes in [flutter/tests] repo.
1 parent 65328cd commit 2fa5ce4

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

shell/platform/windows/window_win32.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,9 @@ void WindowWin32::OnImeComposition(UINT const message,
233233
OnComposeCommit();
234234
}
235235

236-
if (lparam & GCS_COMPSTR) {
237-
// Read the in-progress composing string.
238-
long pos = text_input_manager_->GetComposingCursorPosition();
239-
std::optional<std::u16string> text =
240-
text_input_manager_->GetComposingString();
241-
if (text) {
242-
OnComposeChange(text.value(), pos);
243-
}
244-
}
236+
// Process GCS_RESULTSTR at fisrt, because Google Japanese Input and ATOK send
237+
// both GCS_RESULTSTR and GCS_COMPSTR to commit composed text and send new
238+
// composing text.
245239
if (lparam & GCS_RESULTSTR) {
246240
// Commit but don't end composing.
247241
// Read the committed composing string.
@@ -252,6 +246,15 @@ void WindowWin32::OnImeComposition(UINT const message,
252246
OnComposeCommit();
253247
}
254248
}
249+
if (lparam & GCS_COMPSTR) {
250+
// Read the in-progress composing string.
251+
long pos = text_input_manager_->GetComposingCursorPosition();
252+
std::optional<std::u16string> text =
253+
text_input_manager_->GetComposingString();
254+
if (text) {
255+
OnComposeChange(text.value(), pos);
256+
}
257+
}
255258
}
256259

257260
void WindowWin32::OnImeEndComposition(UINT const message,

shell/platform/windows/window_win32_unittests.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "gtest/gtest.h"
88

99
using testing::_;
10+
using testing::InSequence;
1011
using testing::Invoke;
1112
using testing::Return;
1213

@@ -87,24 +88,34 @@ TEST(MockWin32Window, OnImeCompositionResult) {
8788
window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_RESULTSTR);
8889
}
8990

90-
TEST(MockWin32Window, OnImeCompositionComposeAndResult) {
91+
TEST(MockWin32Window, OnImeCompositionResultAndCompose) {
9192
MockTextInputManagerWin32* text_input_manager =
9293
new MockTextInputManagerWin32();
9394
std::unique_ptr<TextInputManagerWin32> text_input_manager_ptr(
9495
text_input_manager);
9596
MockWin32Window window(std::move(text_input_manager_ptr));
96-
EXPECT_CALL(*text_input_manager, GetComposingString())
97-
.WillRepeatedly(
98-
Return(std::optional<std::u16string>(std::u16string(u"nihao"))));
99-
EXPECT_CALL(*text_input_manager, GetResultString())
100-
.WillRepeatedly(
101-
Return(std::optional<std::u16string>(std::u16string(u"`}"))));
97+
98+
// This situation is that Google Japanese Input finished composing "今日" in
99+
// "今日は" but is still composing "は".
100+
{
101+
InSequence dummy;
102+
EXPECT_CALL(*text_input_manager, GetResultString())
103+
.WillRepeatedly(
104+
Return(std::optional<std::u16string>(std::u16string(u"今日"))));
105+
EXPECT_CALL(*text_input_manager, GetComposingString())
106+
.WillRepeatedly(
107+
Return(std::optional<std::u16string>(std::u16string(u""))));
108+
}
109+
{
110+
InSequence dummy;
111+
EXPECT_CALL(window, OnComposeChange(std::u16string(u"今日"), 0)).Times(1);
112+
EXPECT_CALL(window, OnComposeCommit()).Times(1);
113+
EXPECT_CALL(window, OnComposeChange(std::u16string(u""), 0)).Times(1);
114+
}
115+
102116
EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
103117
.WillRepeatedly(Return((int)0));
104118

105-
EXPECT_CALL(window, OnComposeChange(std::u16string(u"nihao"), 0)).Times(1);
106-
EXPECT_CALL(window, OnComposeChange(std::u16string(u"`}"), 0)).Times(1);
107-
EXPECT_CALL(window, OnComposeCommit()).Times(1);
108119
ON_CALL(window, OnImeComposition)
109120
.WillByDefault(Invoke(&window, &MockWin32Window::CallOnImeComposition));
110121
EXPECT_CALL(window, OnImeComposition(_, _, _)).Times(1);

0 commit comments

Comments
 (0)