diff --git a/engine/src/flutter/shell/platform/common/cpp/text_input_model.cc b/engine/src/flutter/shell/platform/common/cpp/text_input_model.cc index 67f04559b6..31682fbb51 100644 --- a/engine/src/flutter/shell/platform/common/cpp/text_input_model.cc +++ b/engine/src/flutter/shell/platform/common/cpp/text_input_model.cc @@ -29,12 +29,8 @@ bool IsTrailingSurrogate(char32_t code_point) { } // namespace -TextInputModel::TextInputModel(const std::string& input_type, - const std::string& input_action) - : input_type_(input_type), - input_action_(input_action), - selection_base_(text_.begin()), - selection_extent_(text_.begin()) {} +TextInputModel::TextInputModel() + : selection_base_(text_.begin()), selection_extent_(text_.begin()) {} TextInputModel::~TextInputModel() = default; diff --git a/engine/src/flutter/shell/platform/common/cpp/text_input_model.h b/engine/src/flutter/shell/platform/common/cpp/text_input_model.h index 4494dca4c3..387e8d3ac9 100644 --- a/engine/src/flutter/shell/platform/common/cpp/text_input_model.h +++ b/engine/src/flutter/shell/platform/common/cpp/text_input_model.h @@ -14,8 +14,7 @@ namespace flutter { // Ignores special states like "insert mode" for now. class TextInputModel { public: - TextInputModel(const std::string& input_type, - const std::string& input_action); + TextInputModel(); virtual ~TextInputModel(); // Attempts to set the text state. @@ -111,20 +110,10 @@ class TextInputModel { return static_cast(selection_extent_ - text_.begin()); } - // Keyboard type of the client. See available options: - // https://docs.flutter.io/flutter/services/TextInputType-class.html - std::string input_type() const { return input_type_; } - - // An action requested by the user on the input client. See available options: - // https://docs.flutter.io/flutter/services/TextInputAction-class.html - std::string input_action() const { return input_action_; } - private: void DeleteSelected(); std::u16string text_; - std::string input_type_; - std::string input_action_; std::u16string::iterator selection_base_; std::u16string::iterator selection_extent_; }; diff --git a/engine/src/flutter/shell/platform/common/cpp/text_input_model_unittests.cc b/engine/src/flutter/shell/platform/common/cpp/text_input_model_unittests.cc index 09eac75e7e..9b2889459f 100644 --- a/engine/src/flutter/shell/platform/common/cpp/text_input_model_unittests.cc +++ b/engine/src/flutter/shell/platform/common/cpp/text_input_model_unittests.cc @@ -12,14 +12,8 @@ namespace flutter { -TEST(TextInputModel, InputTypeAndAction) { - auto model = std::make_unique("INPUT_TYPE", "INPUT_ACTION"); - EXPECT_STREQ(model->input_type().c_str(), "INPUT_TYPE"); - EXPECT_STREQ(model->input_action().c_str(), "INPUT_ACTION"); -} - TEST(TextInputModel, SetEditingStateStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(0, 0, "ABCDE")); EXPECT_EQ(model->selection_base(), 0); EXPECT_EQ(model->selection_extent(), 0); @@ -27,7 +21,7 @@ TEST(TextInputModel, SetEditingStateStart) { } TEST(TextInputModel, SetEditingMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(2, 2, "ABCDE")); EXPECT_EQ(model->selection_base(), 2); EXPECT_EQ(model->selection_extent(), 2); @@ -35,7 +29,7 @@ TEST(TextInputModel, SetEditingMiddle) { } TEST(TextInputModel, SetEditingStateEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(5, 5, "ABCDE")); EXPECT_EQ(model->selection_base(), 5); EXPECT_EQ(model->selection_extent(), 5); @@ -43,7 +37,7 @@ TEST(TextInputModel, SetEditingStateEnd) { } TEST(TextInputModel, SetEditingStateSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); EXPECT_EQ(model->selection_base(), 1); EXPECT_EQ(model->selection_extent(), 4); @@ -51,19 +45,19 @@ TEST(TextInputModel, SetEditingStateSelection) { } TEST(TextInputModel, SetEditingStateReverseSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_FALSE(model->SetEditingState(3, 1, "ABCDE")); } TEST(TextInputModel, SetEditingStateOutsideString) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_FALSE(model->SetEditingState(4, 6, "ABCDE")); EXPECT_FALSE(model->SetEditingState(5, 6, "ABCDE")); EXPECT_FALSE(model->SetEditingState(6, 6, "ABCDE")); } TEST(TextInputModel, SetEditingStateWideCharacters) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(0, 0, "๐Ÿ˜„๐Ÿ™ƒ๐Ÿคช๐Ÿง")); EXPECT_EQ(model->selection_base(), 0); EXPECT_EQ(model->selection_extent(), 0); @@ -71,7 +65,7 @@ TEST(TextInputModel, SetEditingStateWideCharacters) { } TEST(TextInputModel, AddCodePoint) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->AddCodePoint('A'); model->AddCodePoint('B'); model->AddCodePoint(0x1f604); @@ -83,7 +77,7 @@ TEST(TextInputModel, AddCodePoint) { } TEST(TextInputModel, AddCodePointSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); model->AddCodePoint('x'); EXPECT_EQ(model->selection_base(), 2); @@ -92,7 +86,7 @@ TEST(TextInputModel, AddCodePointSelection) { } TEST(TextInputModel, AddCodePointSelectionWideCharacter) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); model->AddCodePoint(0x1f604); EXPECT_EQ(model->selection_base(), 3); @@ -101,7 +95,7 @@ TEST(TextInputModel, AddCodePointSelectionWideCharacter) { } TEST(TextInputModel, AddText) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->AddText(u"ABCDE"); model->AddText("๐Ÿ˜„"); model->AddText("FGHIJ"); @@ -111,7 +105,7 @@ TEST(TextInputModel, AddText) { } TEST(TextInputModel, AddTextSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); model->AddText("xy"); EXPECT_EQ(model->selection_base(), 3); @@ -120,7 +114,7 @@ TEST(TextInputModel, AddTextSelection) { } TEST(TextInputModel, AddTextSelectionWideCharacter) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); model->AddText(u"๐Ÿ˜„๐Ÿ™ƒ"); EXPECT_EQ(model->selection_base(), 5); @@ -129,7 +123,7 @@ TEST(TextInputModel, AddTextSelectionWideCharacter) { } TEST(TextInputModel, DeleteStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(0, 0, "ABCDE")); ASSERT_TRUE(model->Delete()); EXPECT_EQ(model->selection_base(), 0); @@ -138,7 +132,7 @@ TEST(TextInputModel, DeleteStart) { } TEST(TextInputModel, DeleteMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(2, 2, "ABCDE")); ASSERT_TRUE(model->Delete()); EXPECT_EQ(model->selection_base(), 2); @@ -147,7 +141,7 @@ TEST(TextInputModel, DeleteMiddle) { } TEST(TextInputModel, DeleteEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(5, 5, "ABCDE")); ASSERT_FALSE(model->Delete()); EXPECT_EQ(model->selection_base(), 5); @@ -156,7 +150,7 @@ TEST(TextInputModel, DeleteEnd) { } TEST(TextInputModel, DeleteWideCharacters) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(4, 4, "๐Ÿ˜„๐Ÿ™ƒ๐Ÿคช๐Ÿง")); ASSERT_TRUE(model->Delete()); EXPECT_EQ(model->selection_base(), 4); @@ -165,7 +159,7 @@ TEST(TextInputModel, DeleteWideCharacters) { } TEST(TextInputModel, DeleteSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); ASSERT_TRUE(model->Delete()); EXPECT_EQ(model->selection_base(), 1); @@ -174,7 +168,7 @@ TEST(TextInputModel, DeleteSelection) { } TEST(TextInputModel, DeleteSurroundingAtCursor) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(0, 1)); EXPECT_EQ(model->selection_base(), 2); @@ -183,7 +177,7 @@ TEST(TextInputModel, DeleteSurroundingAtCursor) { } TEST(TextInputModel, DeleteSurroundingAtCursorAll) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(0, 3)); EXPECT_EQ(model->selection_base(), 2); @@ -192,7 +186,7 @@ TEST(TextInputModel, DeleteSurroundingAtCursorAll) { } TEST(TextInputModel, DeleteSurroundingAtCursorGreedy) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(0, 4)); EXPECT_EQ(model->selection_base(), 2); @@ -201,7 +195,7 @@ TEST(TextInputModel, DeleteSurroundingAtCursorGreedy) { } TEST(TextInputModel, DeleteSurroundingBeforeCursor) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(-1, 1)); EXPECT_EQ(model->selection_base(), 1); @@ -210,7 +204,7 @@ TEST(TextInputModel, DeleteSurroundingBeforeCursor) { } TEST(TextInputModel, DeleteSurroundingBeforeCursorAll) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(-2, 2)); EXPECT_EQ(model->selection_base(), 0); @@ -219,7 +213,7 @@ TEST(TextInputModel, DeleteSurroundingBeforeCursorAll) { } TEST(TextInputModel, DeleteSurroundingBeforeCursorGreedy) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(-3, 3)); EXPECT_EQ(model->selection_base(), 0); @@ -228,7 +222,7 @@ TEST(TextInputModel, DeleteSurroundingBeforeCursorGreedy) { } TEST(TextInputModel, DeleteSurroundingAfterCursor) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(1, 1)); EXPECT_EQ(model->selection_base(), 2); @@ -237,7 +231,7 @@ TEST(TextInputModel, DeleteSurroundingAfterCursor) { } TEST(TextInputModel, DeleteSurroundingAfterCursorAll) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(1, 2)); EXPECT_EQ(model->selection_base(), 2); @@ -246,7 +240,7 @@ TEST(TextInputModel, DeleteSurroundingAfterCursorAll) { } TEST(TextInputModel, DeleteSurroundingAfterCursorGreedy) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(1, 3)); EXPECT_EQ(model->selection_base(), 2); @@ -255,7 +249,7 @@ TEST(TextInputModel, DeleteSurroundingAfterCursorGreedy) { } TEST(TextInputModel, DeleteSurroundingSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 3, "ABCDE"); EXPECT_TRUE(model->DeleteSurrounding(0, 1)); EXPECT_EQ(model->selection_base(), 3); @@ -264,7 +258,7 @@ TEST(TextInputModel, DeleteSurroundingSelection) { } TEST(TextInputModel, BackspaceStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(0, 0, "ABCDE")); ASSERT_FALSE(model->Backspace()); EXPECT_EQ(model->selection_base(), 0); @@ -273,7 +267,7 @@ TEST(TextInputModel, BackspaceStart) { } TEST(TextInputModel, BackspaceMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(2, 2, "ABCDE")); ASSERT_TRUE(model->Backspace()); EXPECT_EQ(model->selection_base(), 1); @@ -282,7 +276,7 @@ TEST(TextInputModel, BackspaceMiddle) { } TEST(TextInputModel, BackspaceEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(5, 5, "ABCDE")); ASSERT_TRUE(model->Backspace()); EXPECT_EQ(model->selection_base(), 4); @@ -291,7 +285,7 @@ TEST(TextInputModel, BackspaceEnd) { } TEST(TextInputModel, BackspaceWideCharacters) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(4, 4, "๐Ÿ˜„๐Ÿ™ƒ๐Ÿคช๐Ÿง")); ASSERT_TRUE(model->Backspace()); EXPECT_EQ(model->selection_base(), 2); @@ -300,7 +294,7 @@ TEST(TextInputModel, BackspaceWideCharacters) { } TEST(TextInputModel, BackspaceSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); ASSERT_TRUE(model->Delete()); EXPECT_EQ(model->selection_base(), 1); @@ -309,7 +303,7 @@ TEST(TextInputModel, BackspaceSelection) { } TEST(TextInputModel, MoveCursorForwardStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(0, 0, "ABCDE")); EXPECT_TRUE(model->MoveCursorForward()); EXPECT_EQ(model->selection_base(), 1); @@ -318,7 +312,7 @@ TEST(TextInputModel, MoveCursorForwardStart) { } TEST(TextInputModel, MoveCursorForwardMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(2, 2, "ABCDE")); EXPECT_TRUE(model->MoveCursorForward()); EXPECT_EQ(model->selection_base(), 3); @@ -327,7 +321,7 @@ TEST(TextInputModel, MoveCursorForwardMiddle) { } TEST(TextInputModel, MoveCursorForwardEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(5, 5, "ABCDE")); EXPECT_FALSE(model->MoveCursorForward()); EXPECT_EQ(model->selection_base(), 5); @@ -336,7 +330,7 @@ TEST(TextInputModel, MoveCursorForwardEnd) { } TEST(TextInputModel, MoveCursorForwardWideCharacters) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(4, 4, "๐Ÿ˜„๐Ÿ™ƒ๐Ÿคช๐Ÿง")); ASSERT_TRUE(model->MoveCursorForward()); EXPECT_EQ(model->selection_base(), 6); @@ -345,7 +339,7 @@ TEST(TextInputModel, MoveCursorForwardWideCharacters) { } TEST(TextInputModel, MoveCursorForwardSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(1, 4, "ABCDE")); EXPECT_TRUE(model->MoveCursorForward()); EXPECT_EQ(model->selection_base(), 4); @@ -354,7 +348,7 @@ TEST(TextInputModel, MoveCursorForwardSelection) { } TEST(TextInputModel, MoveCursorBackStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(0, 0, "ABCDE")); EXPECT_FALSE(model->MoveCursorBack()); EXPECT_EQ(model->selection_base(), 0); @@ -363,7 +357,7 @@ TEST(TextInputModel, MoveCursorBackStart) { } TEST(TextInputModel, MoveCursorBackMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->MoveCursorBack()); EXPECT_EQ(model->selection_base(), 1); @@ -372,7 +366,7 @@ TEST(TextInputModel, MoveCursorBackMiddle) { } TEST(TextInputModel, MoveCursorBackEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(5, 5, "ABCDE"); EXPECT_TRUE(model->MoveCursorBack()); EXPECT_EQ(model->selection_base(), 4); @@ -381,7 +375,7 @@ TEST(TextInputModel, MoveCursorBackEnd) { } TEST(TextInputModel, MoveCursorBackWideCharacters) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); EXPECT_TRUE(model->SetEditingState(4, 4, "๐Ÿ˜„๐Ÿ™ƒ๐Ÿคช๐Ÿง")); ASSERT_TRUE(model->MoveCursorBack()); EXPECT_EQ(model->selection_base(), 2); @@ -390,7 +384,7 @@ TEST(TextInputModel, MoveCursorBackWideCharacters) { } TEST(TextInputModel, MoveCursorBackSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(1, 4, "ABCDE"); EXPECT_TRUE(model->MoveCursorBack()); EXPECT_EQ(model->selection_base(), 1); @@ -399,7 +393,7 @@ TEST(TextInputModel, MoveCursorBackSelection) { } TEST(TextInputModel, MoveCursorToBeginningStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(0, 0, "ABCDE"); EXPECT_FALSE(model->MoveCursorToBeginning()); EXPECT_EQ(model->selection_base(), 0); @@ -408,7 +402,7 @@ TEST(TextInputModel, MoveCursorToBeginningStart) { } TEST(TextInputModel, MoveCursorToBeginningMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->MoveCursorToBeginning()); EXPECT_EQ(model->selection_base(), 0); @@ -417,7 +411,7 @@ TEST(TextInputModel, MoveCursorToBeginningMiddle) { } TEST(TextInputModel, MoveCursorToBeginningEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(5, 5, "ABCDE"); EXPECT_TRUE(model->MoveCursorToBeginning()); EXPECT_EQ(model->selection_base(), 0); @@ -426,7 +420,7 @@ TEST(TextInputModel, MoveCursorToBeginningEnd) { } TEST(TextInputModel, MoveCursorToBeginningSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(1, 4, "ABCDE"); EXPECT_TRUE(model->MoveCursorToBeginning()); EXPECT_EQ(model->selection_base(), 0); @@ -435,7 +429,7 @@ TEST(TextInputModel, MoveCursorToBeginningSelection) { } TEST(TextInputModel, MoveCursorToEndStart) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(0, 0, "ABCDE"); EXPECT_TRUE(model->MoveCursorToEnd()); EXPECT_EQ(model->selection_base(), 5); @@ -444,7 +438,7 @@ TEST(TextInputModel, MoveCursorToEndStart) { } TEST(TextInputModel, MoveCursorToEndMiddle) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(2, 2, "ABCDE"); EXPECT_TRUE(model->MoveCursorToEnd()); EXPECT_EQ(model->selection_base(), 5); @@ -453,7 +447,7 @@ TEST(TextInputModel, MoveCursorToEndMiddle) { } TEST(TextInputModel, MoveCursorToEndEnd) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(5, 5, "ABCDE"); EXPECT_FALSE(model->MoveCursorToEnd()); EXPECT_EQ(model->selection_base(), 5); @@ -462,7 +456,7 @@ TEST(TextInputModel, MoveCursorToEndEnd) { } TEST(TextInputModel, MoveCursorToEndSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(1, 4, "ABCDE"); EXPECT_TRUE(model->MoveCursorToEnd()); EXPECT_EQ(model->selection_base(), 5); @@ -471,7 +465,7 @@ TEST(TextInputModel, MoveCursorToEndSelection) { } TEST(TextInputModel, GetCursorOffset) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); // These characters take 1, 2, 3 and 4 bytes in UTF-8. model->SetEditingState(0, 0, "$ยขโ‚ฌ๐ˆ"); EXPECT_EQ(model->GetCursorOffset(), 0); @@ -486,7 +480,7 @@ TEST(TextInputModel, GetCursorOffset) { } TEST(TextInputModel, GetCursorOffsetSelection) { - auto model = std::make_unique("", ""); + auto model = std::make_unique(); model->SetEditingState(1, 4, "ABCDE"); EXPECT_EQ(model->GetCursorOffset(), 4); } diff --git a/engine/src/flutter/shell/platform/glfw/text_input_plugin.cc b/engine/src/flutter/shell/platform/glfw/text_input_plugin.cc index 484c6c8dd4..760bea2ce8 100644 --- a/engine/src/flutter/shell/platform/glfw/text_input_plugin.cc +++ b/engine/src/flutter/shell/platform/glfw/text_input_plugin.cc @@ -141,13 +141,13 @@ void TextInputPlugin::HandleMethodCall( "Could not set client, missing arguments."); } client_id_ = client_id_json.GetInt(); - std::string input_action; + input_action_ = ""; auto input_action_json = client_config.FindMember(kTextInputAction); if (input_action_json != client_config.MemberEnd() && input_action_json->value.IsString()) { - input_action = input_action_json->value.GetString(); + input_action_ = input_action_json->value.GetString(); } - std::string input_type; + input_type_ = ""; auto input_type_info_json = client_config.FindMember(kTextInputType); if (input_type_info_json != client_config.MemberEnd() && input_type_info_json->value.IsObject()) { @@ -155,10 +155,10 @@ void TextInputPlugin::HandleMethodCall( input_type_info_json->value.FindMember(kTextInputTypeName); if (input_type_json != input_type_info_json->value.MemberEnd() && input_type_json->value.IsString()) { - input_type = input_type_json->value.GetString(); + input_type_ = input_type_json->value.GetString(); } } - active_model_ = std::make_unique(input_type, input_action); + active_model_ = std::make_unique(); } else if (method.compare(kSetEditingStateMethod) == 0) { if (!method_call.arguments() || method_call.arguments()->IsNull()) { result->Error(kBadArgumentError, "Method invoked without args"); @@ -221,15 +221,14 @@ void TextInputPlugin::SendStateUpdate(const TextInputModel& model) { } void TextInputPlugin::EnterPressed(TextInputModel* model) { - if (model->input_type() == kMultilineInputType) { + if (input_type_ == kMultilineInputType) { model->AddCodePoint('\n'); SendStateUpdate(*model); } auto args = std::make_unique(rapidjson::kArrayType); auto& allocator = args->GetAllocator(); args->PushBack(client_id_, allocator); - args->PushBack(rapidjson::Value(model->input_action(), allocator).Move(), - allocator); + args->PushBack(rapidjson::Value(input_action_, allocator).Move(), allocator); channel_->InvokeMethod(kPerformActionMethod, std::move(args)); } diff --git a/engine/src/flutter/shell/platform/glfw/text_input_plugin.h b/engine/src/flutter/shell/platform/glfw/text_input_plugin.h index 00c9a732c4..29579c8471 100644 --- a/engine/src/flutter/shell/platform/glfw/text_input_plugin.h +++ b/engine/src/flutter/shell/platform/glfw/text_input_plugin.h @@ -57,6 +57,14 @@ class TextInputPlugin : public KeyboardHookHandler { // The active model. nullptr if not set. std::unique_ptr active_model_; + + // Keyboard type of the client. See available options: + // https://docs.flutter.io/flutter/services/TextInputType-class.html + std::string input_type_; + + // An action requested by the user on the input client. See available options: + // https://docs.flutter.io/flutter/services/TextInputAction-class.html + std::string input_action_; }; } // namespace flutter diff --git a/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc b/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc index d9ba082918..e615fda352 100644 --- a/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc +++ b/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc @@ -267,7 +267,7 @@ static void fl_text_input_plugin_init(FlTextInputPlugin* self) { g_signal_connect_object(self->im_context, "delete-surrounding", G_CALLBACK(im_delete_surrounding_cb), self, G_CONNECT_SWAPPED); - self->text_model = new flutter::TextInputModel("", ""); + self->text_model = new flutter::TextInputModel(); } FlTextInputPlugin* fl_text_input_plugin_new(FlBinaryMessenger* messenger) { diff --git a/engine/src/flutter/shell/platform/windows/text_input_plugin.cc b/engine/src/flutter/shell/platform/windows/text_input_plugin.cc index 36f6389f8a..7f3127a286 100644 --- a/engine/src/flutter/shell/platform/windows/text_input_plugin.cc +++ b/engine/src/flutter/shell/platform/windows/text_input_plugin.cc @@ -143,13 +143,13 @@ void TextInputPlugin::HandleMethodCall( return; } client_id_ = client_id_json.GetInt(); - std::string input_action; + input_action_ = ""; auto input_action_json = client_config.FindMember(kTextInputAction); if (input_action_json != client_config.MemberEnd() && input_action_json->value.IsString()) { - input_action = input_action_json->value.GetString(); + input_action_ = input_action_json->value.GetString(); } - std::string input_type; + input_type_ = ""; auto input_type_info_json = client_config.FindMember(kTextInputType); if (input_type_info_json != client_config.MemberEnd() && input_type_info_json->value.IsObject()) { @@ -157,10 +157,10 @@ void TextInputPlugin::HandleMethodCall( input_type_info_json->value.FindMember(kTextInputTypeName); if (input_type_json != input_type_info_json->value.MemberEnd() && input_type_json->value.IsString()) { - input_type = input_type_json->value.GetString(); + input_type_ = input_type_json->value.GetString(); } } - active_model_ = std::make_unique(input_type, input_action); + active_model_ = std::make_unique(); } else if (method.compare(kSetEditingStateMethod) == 0) { if (!method_call.arguments() || method_call.arguments()->IsNull()) { result->Error(kBadArgumentError, "Method invoked without args"); @@ -223,15 +223,14 @@ void TextInputPlugin::SendStateUpdate(const TextInputModel& model) { } void TextInputPlugin::EnterPressed(TextInputModel* model) { - if (model->input_type() == kMultilineInputType) { + if (input_type_ == kMultilineInputType) { model->AddText(std::u16string({u'\n'})); SendStateUpdate(*model); } auto args = std::make_unique(rapidjson::kArrayType); auto& allocator = args->GetAllocator(); args->PushBack(client_id_, allocator); - args->PushBack(rapidjson::Value(model->input_action(), allocator).Move(), - allocator); + args->PushBack(rapidjson::Value(input_action_, allocator).Move(), allocator); channel_->InvokeMethod(kPerformActionMethod, std::move(args)); } diff --git a/engine/src/flutter/shell/platform/windows/text_input_plugin.h b/engine/src/flutter/shell/platform/windows/text_input_plugin.h index 9000da7e07..5acdaf25de 100644 --- a/engine/src/flutter/shell/platform/windows/text_input_plugin.h +++ b/engine/src/flutter/shell/platform/windows/text_input_plugin.h @@ -59,6 +59,14 @@ class TextInputPlugin : public KeyboardHookHandler { // The active model. nullptr if not set. std::unique_ptr active_model_; + + // Keyboard type of the client. See available options: + // https://docs.flutter.io/flutter/services/TextInputType-class.html + std::string input_type_; + + // An action requested by the user on the input client. See available options: + // https://docs.flutter.io/flutter/services/TextInputAction-class.html + std::string input_action_; }; } // namespace flutter