From 23d52615ac8959b6ce04083ab6c3223eb6300df0 Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 4 Mar 2024 16:41:11 +0900 Subject: [PATCH 1/7] Reverts the logic for calculating the TextField input text cursor position when inputting Korean characters (as 3.13.9) - Issue occurred since 3.16.x - https://github.com/flutter/flutter/issues/140739 --- shell/platform/common/text_input_model.cc | 5 +++++ shell/platform/windows/text_input_plugin.cc | 1 + 2 files changed, 6 insertions(+) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index a21fe1ff3effa..4748da32d6055 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -8,6 +8,7 @@ #include #include "flutter/fml/string_conversion.h" +#include "flutter/fml/build_config.h" namespace flutter { @@ -79,8 +80,12 @@ void TextInputModel::UpdateComposingText(const std::u16string& text, composing_range_.collapsed() ? selection_ : composing_range_; text_.replace(rangeToDelete.start(), rangeToDelete.length(), text); composing_range_.set_end(composing_range_.start() + text.length()); +#if FML_OS_WIN + selection_ = TextRange(composing_range_.end()); +#else // FML_OS_WIN selection_ = TextRange(selection.start() + composing_range_.start(), selection.extent() + composing_range_.start()); +#endif // FML_OS_WIN } void TextInputModel::UpdateComposingText(const std::u16string& text) { diff --git a/shell/platform/windows/text_input_plugin.cc b/shell/platform/windows/text_input_plugin.cc index a67eca476c7e0..8d3e545659983 100644 --- a/shell/platform/windows/text_input_plugin.cc +++ b/shell/platform/windows/text_input_plugin.cc @@ -197,6 +197,7 @@ void TextInputPlugin::ComposeChangeHook(const std::u16string& text, std::string text_before_change = active_model_->GetText(); TextRange composing_before_change = active_model_->composing_range(); active_model_->AddText(text); + cursor_pos += active_model_->composing_range().extent(); active_model_->UpdateComposingText(text, TextRange(cursor_pos, cursor_pos)); std::string text_after_change = active_model_->GetText(); if (enable_delta_model) { From 5926fa90fd70cb262e379d9386a1dfd4ee5bc2cf Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 4 Mar 2024 16:45:41 +0900 Subject: [PATCH 2/7] modify header includes --- shell/platform/common/text_input_model.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index 4748da32d6055..48956a8089613 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -7,8 +7,8 @@ #include #include -#include "flutter/fml/string_conversion.h" #include "flutter/fml/build_config.h" +#include "flutter/fml/string_conversion.h" namespace flutter { From bc80cd9fff9357077bd74ce801c6a5ee85b69abe Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 11 Mar 2024 10:57:21 +0900 Subject: [PATCH 3/7] Remove platform branching codes in the common area, add to check korean included in composing text. --- shell/platform/common/text_input_model.cc | 18 +++++++++++++----- shell/platform/windows/text_input_plugin.cc | 2 -- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index 48956a8089613..fc3af14f88adc 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -5,9 +5,9 @@ #include "flutter/shell/platform/common/text_input_model.h" #include +#include #include -#include "flutter/fml/build_config.h" #include "flutter/fml/string_conversion.h" namespace flutter { @@ -80,12 +80,20 @@ void TextInputModel::UpdateComposingText(const std::u16string& text, composing_range_.collapsed() ? selection_ : composing_range_; text_.replace(rangeToDelete.start(), rangeToDelete.length(), text); composing_range_.set_end(composing_range_.start() + text.length()); -#if FML_OS_WIN - selection_ = TextRange(composing_range_.end()); -#else // FML_OS_WIN + selection_ = TextRange(selection.start() + composing_range_.start(), selection.extent() + composing_range_.start()); -#endif // FML_OS_WIN + + bool koreanIncluded = false; + std::u16string composing_texts = text_.substr(composing_range_.start(), text.length()); + if (composing_texts.length() > 0) { + const std::regex _korRegexp("^[ㄱ-ㆎ|가-힣]+$"); + std::string u8string = fml::Utf16ToUtf8(composing_texts); + koreanIncluded = std::regex_match(u8string, _korRegexp); + } + if (koreanIncluded) { + selection_ = TextRange(selection.extent() + composing_range_.end()); + } } void TextInputModel::UpdateComposingText(const std::u16string& text) { diff --git a/shell/platform/windows/text_input_plugin.cc b/shell/platform/windows/text_input_plugin.cc index 8d3e545659983..23d67d8ae2433 100644 --- a/shell/platform/windows/text_input_plugin.cc +++ b/shell/platform/windows/text_input_plugin.cc @@ -197,9 +197,7 @@ void TextInputPlugin::ComposeChangeHook(const std::u16string& text, std::string text_before_change = active_model_->GetText(); TextRange composing_before_change = active_model_->composing_range(); active_model_->AddText(text); - cursor_pos += active_model_->composing_range().extent(); active_model_->UpdateComposingText(text, TextRange(cursor_pos, cursor_pos)); - std::string text_after_change = active_model_->GetText(); if (enable_delta_model) { TextEditingDelta delta = TextEditingDelta( fml::Utf8ToUtf16(text_before_change), composing_before_change, text); From 10aefb30ce0591222649091f04774a173f41f4aa Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 11 Mar 2024 11:00:29 +0900 Subject: [PATCH 4/7] reformatting codes --- shell/platform/common/text_input_model.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index fc3af14f88adc..af5aec85ebfa6 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -84,14 +84,14 @@ void TextInputModel::UpdateComposingText(const std::u16string& text, selection_ = TextRange(selection.start() + composing_range_.start(), selection.extent() + composing_range_.start()); - bool koreanIncluded = false; + bool korean_included = false; std::u16string composing_texts = text_.substr(composing_range_.start(), text.length()); if (composing_texts.length() > 0) { - const std::regex _korRegexp("^[ㄱ-ㆎ|가-힣]+$"); + const std::regex kor_regex("^[ㄱ-ㆎ|가-힣]+$"); std::string u8string = fml::Utf16ToUtf8(composing_texts); - koreanIncluded = std::regex_match(u8string, _korRegexp); + korean_included = std::regex_match(u8string, kor_regex); } - if (koreanIncluded) { + if (korean_included) { selection_ = TextRange(selection.extent() + composing_range_.end()); } } From 9a032ed49a19f41eb02397e5b828c752672f33ec Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 11 Mar 2024 11:08:32 +0900 Subject: [PATCH 5/7] reformatting codes --- shell/platform/common/text_input_model.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index af5aec85ebfa6..ff847e203d3ce 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -85,7 +85,8 @@ void TextInputModel::UpdateComposingText(const std::u16string& text, selection.extent() + composing_range_.start()); bool korean_included = false; - std::u16string composing_texts = text_.substr(composing_range_.start(), text.length()); + std::u16string composing_texts = + text_.substr(composing_range_.start(), text.length()); if (composing_texts.length() > 0) { const std::regex kor_regex("^[ㄱ-ㆎ|가-힣]+$"); std::string u8string = fml::Utf16ToUtf8(composing_texts); From 5387704ce7129efbf79586b0b85e033dbf24a512 Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 11 Mar 2024 16:10:39 +0900 Subject: [PATCH 6/7] Modify checking to korean regular expression to wregex function --- shell/platform/common/text_input_model.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index ff847e203d3ce..7a5a136349f21 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -88,9 +88,8 @@ void TextInputModel::UpdateComposingText(const std::u16string& text, std::u16string composing_texts = text_.substr(composing_range_.start(), text.length()); if (composing_texts.length() > 0) { - const std::regex kor_regex("^[ㄱ-ㆎ|가-힣]+$"); - std::string u8string = fml::Utf16ToUtf8(composing_texts); - korean_included = std::regex_match(u8string, kor_regex); + std::wregex kor_regex(L"[ㄱ-ㅎㅏ-ㅣ가-힣]"); + korean_included = std::regex_match(text.cbegin(), text.cend(), kor_regex); } if (korean_included) { selection_ = TextRange(selection.extent() + composing_range_.end()); From d3640b1ef317b10313340bd3a3d653cc59c404f9 Mon Sep 17 00:00:00 2001 From: "developer.deniz" Date: Mon, 11 Mar 2024 16:15:25 +0900 Subject: [PATCH 7/7] Remove unused variable. --- shell/platform/common/text_input_model.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shell/platform/common/text_input_model.cc b/shell/platform/common/text_input_model.cc index 7a5a136349f21..bbd67cdaf92da 100644 --- a/shell/platform/common/text_input_model.cc +++ b/shell/platform/common/text_input_model.cc @@ -85,9 +85,7 @@ void TextInputModel::UpdateComposingText(const std::u16string& text, selection.extent() + composing_range_.start()); bool korean_included = false; - std::u16string composing_texts = - text_.substr(composing_range_.start(), text.length()); - if (composing_texts.length() > 0) { + if (text.length() > 0) { std::wregex kor_regex(L"[ㄱ-ㅎㅏ-ㅣ가-힣]"); korean_included = std::regex_match(text.cbegin(), text.cend(), kor_regex); }