Remove the input type and action from TextInputModel. (flutter/engine#18919)

These aren't used by the model so are better managed outside of it.
This commit is contained in:
Robert Ancell
2020-06-10 10:00:32 +12:00
committed by GitHub
parent 6eb606d225
commit cd9cb596eb
8 changed files with 87 additions and 94 deletions

View File

@@ -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;

View File

@@ -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<int>(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_;
};

View File

@@ -12,14 +12,8 @@
namespace flutter {
TEST(TextInputModel, InputTypeAndAction) {
auto model = std::make_unique<TextInputModel>("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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
EXPECT_FALSE(model->SetEditingState(3, 1, "ABCDE"));
}
TEST(TextInputModel, SetEditingStateOutsideString) {
auto model = std::make_unique<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
model->AddCodePoint('A');
model->AddCodePoint('B');
model->AddCodePoint(0x1f604);
@@ -83,7 +77,7 @@ TEST(TextInputModel, AddCodePoint) {
}
TEST(TextInputModel, AddCodePointSelection) {
auto model = std::make_unique<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
model->AddText(u"ABCDE");
model->AddText("😄");
model->AddText("FGHIJ");
@@ -111,7 +105,7 @@ TEST(TextInputModel, AddText) {
}
TEST(TextInputModel, AddTextSelection) {
auto model = std::make_unique<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
// 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<TextInputModel>("", "");
auto model = std::make_unique<TextInputModel>();
model->SetEditingState(1, 4, "ABCDE");
EXPECT_EQ(model->GetCursorOffset(), 4);
}

View File

@@ -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<TextInputModel>(input_type, input_action);
active_model_ = std::make_unique<TextInputModel>();
} 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::Document>(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));
}

View File

@@ -57,6 +57,14 @@ class TextInputPlugin : public KeyboardHookHandler {
// The active model. nullptr if not set.
std::unique_ptr<TextInputModel> 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

View File

@@ -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) {

View File

@@ -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<TextInputModel>(input_type, input_action);
active_model_ = std::make_unique<TextInputModel>();
} 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::Document>(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));
}

View File

@@ -59,6 +59,14 @@ class TextInputPlugin : public KeyboardHookHandler {
// The active model. nullptr if not set.
std::unique_ptr<TextInputModel> 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