[Windows] Google Japanese Input, composing text doesn't rendered after commit text partially (flutter/engine#33605)

Reproducible steps is in flutter/flutter#102021.

Fixes flutter/flutter#102021.

No changes in [flutter/tests] repo.
This commit is contained in:
moko256 2022-06-01 10:01:55 +09:00 committed by GitHub
parent 368b5cc6a8
commit 601e178945
2 changed files with 33 additions and 19 deletions

View File

@ -233,15 +233,9 @@ void WindowWin32::OnImeComposition(UINT const message,
OnComposeCommit();
}
if (lparam & GCS_COMPSTR) {
// Read the in-progress composing string.
long pos = text_input_manager_->GetComposingCursorPosition();
std::optional<std::u16string> text =
text_input_manager_->GetComposingString();
if (text) {
OnComposeChange(text.value(), pos);
}
}
// Process GCS_RESULTSTR at fisrt, because Google Japanese Input and ATOK send
// both GCS_RESULTSTR and GCS_COMPSTR to commit composed text and send new
// composing text.
if (lparam & GCS_RESULTSTR) {
// Commit but don't end composing.
// Read the committed composing string.
@ -252,6 +246,15 @@ void WindowWin32::OnImeComposition(UINT const message,
OnComposeCommit();
}
}
if (lparam & GCS_COMPSTR) {
// Read the in-progress composing string.
long pos = text_input_manager_->GetComposingCursorPosition();
std::optional<std::u16string> text =
text_input_manager_->GetComposingString();
if (text) {
OnComposeChange(text.value(), pos);
}
}
}
void WindowWin32::OnImeEndComposition(UINT const message,

View File

@ -7,6 +7,7 @@
#include "gtest/gtest.h"
using testing::_;
using testing::InSequence;
using testing::Invoke;
using testing::Return;
@ -87,24 +88,34 @@ TEST(MockWin32Window, OnImeCompositionResult) {
window.InjectWindowMessage(WM_IME_COMPOSITION, 0, GCS_RESULTSTR);
}
TEST(MockWin32Window, OnImeCompositionComposeAndResult) {
TEST(MockWin32Window, OnImeCompositionResultAndCompose) {
MockTextInputManagerWin32* text_input_manager =
new MockTextInputManagerWin32();
std::unique_ptr<TextInputManagerWin32> text_input_manager_ptr(
text_input_manager);
MockWin32Window window(std::move(text_input_manager_ptr));
EXPECT_CALL(*text_input_manager, GetComposingString())
.WillRepeatedly(
Return(std::optional<std::u16string>(std::u16string(u"nihao"))));
EXPECT_CALL(*text_input_manager, GetResultString())
.WillRepeatedly(
Return(std::optional<std::u16string>(std::u16string(u"`}"))));
// This situation is that Google Japanese Input finished composing "今日" in
// "今日は" but is still composing "は".
{
InSequence dummy;
EXPECT_CALL(*text_input_manager, GetResultString())
.WillRepeatedly(
Return(std::optional<std::u16string>(std::u16string(u"今日"))));
EXPECT_CALL(*text_input_manager, GetComposingString())
.WillRepeatedly(
Return(std::optional<std::u16string>(std::u16string(u""))));
}
{
InSequence dummy;
EXPECT_CALL(window, OnComposeChange(std::u16string(u"今日"), 0)).Times(1);
EXPECT_CALL(window, OnComposeCommit()).Times(1);
EXPECT_CALL(window, OnComposeChange(std::u16string(u""), 0)).Times(1);
}
EXPECT_CALL(*text_input_manager, GetComposingCursorPosition())
.WillRepeatedly(Return((int)0));
EXPECT_CALL(window, OnComposeChange(std::u16string(u"nihao"), 0)).Times(1);
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);