From cfe03b198b8ea8307bc7dee0f464b516e7cd81a7 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 16:49:37 -0700 Subject: [PATCH 01/17] send correct delta range on preedit changed and send previous text on preedit end and if commiting while composing send composing before change instead of selection before change --- shell/platform/linux/fl_text_input_plugin.cc | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 951e21e249d81..b65950681f4f4 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -255,6 +255,7 @@ static void perform_action(FlTextInputPlugin* self) { static void im_preedit_start_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); + g_warning("preedit started"); priv->text_model->BeginComposing(); } @@ -263,6 +264,7 @@ static void im_preedit_changed_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); + flutter::TextRange composing_before_change = priv->text_model->composing_range(); g_autofree gchar* buf = nullptr; gint cursor_offset = 0; gtk_im_context_get_preedit_string(priv->im_context, &buf, nullptr, @@ -274,11 +276,11 @@ static void im_preedit_changed_cb(FlTextInputPlugin* self) { } priv->text_model->UpdateComposingText(buf); priv->text_model->SetSelection(flutter::TextRange(cursor_offset)); - + g_warning("preedit changed"); if (priv->enable_delta_model) { std::string text(buf); flutter::TextEditingDelta delta = flutter::TextEditingDelta( - text_before_change, priv->text_model->composing_range(), text); + text_before_change, composing_before_change, text); update_editing_state_with_delta(self, &delta); } else { update_editing_state(self); @@ -290,17 +292,27 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); + flutter::TextRange composing_before_change = priv->text_model->composing_range(); flutter::TextRange selection_before_change = priv->text_model->selection(); + gboolean wasComposing = priv->text_model->composing(); priv->text_model->AddText(text); if (priv->text_model->composing()) { priv->text_model->CommitComposing(); } + g_warning("im commit"); if (priv->enable_delta_model) { - flutter::TextEditingDelta delta = flutter::TextEditingDelta( - text_before_change, selection_before_change, text); - update_editing_state_with_delta(self, &delta); + flutter::TextEditingDelta* delta; + if (wasComposing) { + delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); + } else { + delta = new flutter::TextEditingDelta(text_before_change, selection_before_change, text); + } + //flutter::TextEditingDelta delta = flutter::TextEditingDelta( + // text_before_change, selection_before_change, text); + update_editing_state_with_delta(self, delta); + delete delta; } else { update_editing_state(self); } @@ -310,10 +322,12 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { static void im_preedit_end_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); + std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); + g_warning("preedit end"); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = flutter::TextEditingDelta( - "", flutter::TextRange(-1, -1), priv->text_model->GetText()); + text_before_change, flutter::TextRange(-1, -1), priv->text_model->GetText()); update_editing_state_with_delta(self, &delta); } else { update_editing_state(self); From 81e797284ea71b322b95436eadbd598fa392cc6e Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 16:52:04 -0700 Subject: [PATCH 02/17] fix analyzer --- shell/platform/linux/fl_text_input_plugin.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index b65950681f4f4..cea2dcb5affc2 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -276,7 +276,7 @@ static void im_preedit_changed_cb(FlTextInputPlugin* self) { } priv->text_model->UpdateComposingText(buf); priv->text_model->SetSelection(flutter::TextRange(cursor_offset)); - g_warning("preedit changed"); + g_warning("preedit changed"); if (priv->enable_delta_model) { std::string text(buf); flutter::TextEditingDelta delta = flutter::TextEditingDelta( @@ -292,7 +292,7 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); - flutter::TextRange composing_before_change = priv->text_model->composing_range(); + flutter::TextRange composing_before_change = priv->text_model->composing_range(); flutter::TextRange selection_before_change = priv->text_model->selection(); gboolean wasComposing = priv->text_model->composing(); @@ -301,9 +301,9 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { priv->text_model->CommitComposing(); } - g_warning("im commit"); + g_warning("im commit"); if (priv->enable_delta_model) { - flutter::TextEditingDelta* delta; + flutter::TextEditingDelta* delta; if (wasComposing) { delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); } else { @@ -324,7 +324,7 @@ static void im_preedit_end_cb(FlTextInputPlugin* self) { fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); - g_warning("preedit end"); + g_warning("preedit end"); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = flutter::TextEditingDelta( text_before_change, flutter::TextRange(-1, -1), priv->text_model->GetText()); From a4311b68ff3d11aeec780b8f9620a0cd9c388118 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 16:53:11 -0700 Subject: [PATCH 03/17] fix trailing spaces --- shell/platform/linux/fl_text_input_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index cea2dcb5affc2..39cb9d0a78b13 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -305,7 +305,7 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { if (priv->enable_delta_model) { flutter::TextEditingDelta* delta; if (wasComposing) { - delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); + delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); } else { delta = new flutter::TextEditingDelta(text_before_change, selection_before_change, text); } From 5fe5f77942079d0481baf25d014a84a4b4c810af Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 16:57:09 -0700 Subject: [PATCH 04/17] formatting --- shell/platform/linux/fl_text_input_plugin.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 39cb9d0a78b13..a9e3c95a4cda8 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -255,7 +255,7 @@ static void perform_action(FlTextInputPlugin* self) { static void im_preedit_start_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); - g_warning("preedit started"); + g_warning("preedit started"); priv->text_model->BeginComposing(); } @@ -264,7 +264,8 @@ static void im_preedit_changed_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); - flutter::TextRange composing_before_change = priv->text_model->composing_range(); + flutter::TextRange composing_before_change = + priv->text_model->composing_range(); g_autofree gchar* buf = nullptr; gint cursor_offset = 0; gtk_im_context_get_preedit_string(priv->im_context, &buf, nullptr, @@ -292,7 +293,8 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); - flutter::TextRange composing_before_change = priv->text_model->composing_range(); + flutter::TextRange composing_before_change = + priv->text_model->composing_range(); flutter::TextRange selection_before_change = priv->text_model->selection(); gboolean wasComposing = priv->text_model->composing(); @@ -305,12 +307,12 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { if (priv->enable_delta_model) { flutter::TextEditingDelta* delta; if (wasComposing) { - delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); + delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); } else { - delta = new flutter::TextEditingDelta(text_before_change, selection_before_change, text); + delta = new flutter::TextEditingDelta(text_before_change, selection_before_change, text); } - //flutter::TextEditingDelta delta = flutter::TextEditingDelta( - // text_before_change, selection_before_change, text); + // flutter::TextEditingDelta delta = flutter::TextEditingDelta( + // text_before_change, selection_before_change, text); update_editing_state_with_delta(self, delta); delete delta; } else { @@ -327,7 +329,8 @@ static void im_preedit_end_cb(FlTextInputPlugin* self) { g_warning("preedit end"); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = flutter::TextEditingDelta( - text_before_change, flutter::TextRange(-1, -1), priv->text_model->GetText()); + text_before_change, flutter::TextRange(-1, -1), + priv->text_model->GetText()); update_editing_state_with_delta(self, &delta); } else { update_editing_state(self); From 290a5c48eb4c1620a919e0463f8c67de04fbf417 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 16:58:18 -0700 Subject: [PATCH 05/17] more formatting --- shell/platform/linux/fl_text_input_plugin.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index a9e3c95a4cda8..2ad6d0a713d88 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -307,9 +307,11 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { if (priv->enable_delta_model) { flutter::TextEditingDelta* delta; if (wasComposing) { - delta = new flutter::TextEditingDelta(text_before_change, composing_before_change, text); + delta = new flutter::TextEditingDelta(text_before_change, + composing_before_change, text); } else { - delta = new flutter::TextEditingDelta(text_before_change, selection_before_change, text); + delta = new flutter::TextEditingDelta(text_before_change, + selection_before_change, text); } // flutter::TextEditingDelta delta = flutter::TextEditingDelta( // text_before_change, selection_before_change, text); From 4f4f4ce0e24d34c72e05856e3a809dd6161439ad Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 16:59:39 -0700 Subject: [PATCH 06/17] more formatting --- shell/platform/linux/fl_text_input_plugin.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 2ad6d0a713d88..87c89d3111915 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -308,10 +308,10 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { flutter::TextEditingDelta* delta; if (wasComposing) { delta = new flutter::TextEditingDelta(text_before_change, - composing_before_change, text); + composing_before_change, text); } else { delta = new flutter::TextEditingDelta(text_before_change, - selection_before_change, text); + selection_before_change, text); } // flutter::TextEditingDelta delta = flutter::TextEditingDelta( // text_before_change, selection_before_change, text); From bed42da2c313569ff27c13f6c9128557317754b7 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 17:00:50 -0700 Subject: [PATCH 07/17] more formatting --- shell/platform/linux/fl_text_input_plugin.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 87c89d3111915..6e1272508ffa9 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -308,10 +308,10 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { flutter::TextEditingDelta* delta; if (wasComposing) { delta = new flutter::TextEditingDelta(text_before_change, - composing_before_change, text); + composing_before_change, text); } else { delta = new flutter::TextEditingDelta(text_before_change, - selection_before_change, text); + selection_before_change, text); } // flutter::TextEditingDelta delta = flutter::TextEditingDelta( // text_before_change, selection_before_change, text); From 2acbad06f45f486b1c6e0c04dae4c1ef5aeded94 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 7 Jun 2023 19:07:19 -0700 Subject: [PATCH 08/17] remove logs --- shell/platform/linux/fl_text_input_plugin.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 6e1272508ffa9..3d09b4b5a043b 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -255,7 +255,6 @@ static void perform_action(FlTextInputPlugin* self) { static void im_preedit_start_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); - g_warning("preedit started"); priv->text_model->BeginComposing(); } @@ -277,7 +276,6 @@ static void im_preedit_changed_cb(FlTextInputPlugin* self) { } priv->text_model->UpdateComposingText(buf); priv->text_model->SetSelection(flutter::TextRange(cursor_offset)); - g_warning("preedit changed"); if (priv->enable_delta_model) { std::string text(buf); flutter::TextEditingDelta delta = flutter::TextEditingDelta( @@ -303,7 +301,6 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { priv->text_model->CommitComposing(); } - g_warning("im commit"); if (priv->enable_delta_model) { flutter::TextEditingDelta* delta; if (wasComposing) { @@ -313,8 +310,6 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { delta = new flutter::TextEditingDelta(text_before_change, selection_before_change, text); } - // flutter::TextEditingDelta delta = flutter::TextEditingDelta( - // text_before_change, selection_before_change, text); update_editing_state_with_delta(self, delta); delete delta; } else { @@ -328,7 +323,6 @@ static void im_preedit_end_cb(FlTextInputPlugin* self) { fl_text_input_plugin_get_instance_private(self)); std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); - g_warning("preedit end"); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = flutter::TextEditingDelta( text_before_change, flutter::TextRange(-1, -1), From 82d49a69ddfb25e53654bd23dc93844e3e1725cf Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 00:44:40 -0700 Subject: [PATCH 09/17] Fix exisiting test --- shell/platform/linux/fl_text_input_plugin_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_text_input_plugin_test.cc b/shell/platform/linux/fl_text_input_plugin_test.cc index 182e5311ba9bb..4faf103c8f0d7 100644 --- a/shell/platform/linux/fl_text_input_plugin_test.cc +++ b/shell/platform/linux/fl_text_input_plugin_test.cc @@ -976,7 +976,7 @@ TEST(FlTextInputPluginTest, ComposingDelta) { .old_text = "", .delta_text = "Flutter ", .delta_start = 0, - .delta_end = 8, + .delta_end = 0, .selection_base = 8, .selection_extent = 8, .composing_base = 0, @@ -1033,6 +1033,7 @@ TEST(FlTextInputPluginTest, ComposingDelta) { "deltas", build_list({ build_editing_delta({ + .old_text = "Flutter engine", .delta_text = "Flutter engine", .selection_base = 14, .selection_extent = 14, From dfd89c4b41e42dc3afb84a141786179ec3916150 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 03:51:16 -0700 Subject: [PATCH 10/17] Fix existing test and add a test --- .../linux/fl_text_input_plugin_test.cc | 250 +++++++++++++++++- 1 file changed, 245 insertions(+), 5 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin_test.cc b/shell/platform/linux/fl_text_input_plugin_test.cc index 4faf103c8f0d7..08472b8d7d6c3 100644 --- a/shell/platform/linux/fl_text_input_plugin_test.cc +++ b/shell/platform/linux/fl_text_input_plugin_test.cc @@ -958,6 +958,8 @@ TEST(FlTextInputPluginTest, ComposingDelta) { messenger.ReceiveMessage("flutter/textinput", set_client); + g_signal_emit_by_name(context, "preedit-start", nullptr); + // update EXPECT_CALL(context, gtk_im_context_get_preedit_string( @@ -1004,13 +1006,13 @@ TEST(FlTextInputPluginTest, ComposingDelta) { build_list({ build_editing_delta({ .old_text = "Flutter ", - .delta_text = "engine", - .delta_start = 8, + .delta_text = "Flutter engine", + .delta_start = 0, .delta_end = 8, .selection_base = 14, .selection_extent = 14, - .composing_base = 0, - .composing_extent = 8, + .composing_base = -1, + .composing_extent = -1, }), }), }}), @@ -1024,7 +1026,7 @@ TEST(FlTextInputPluginTest, ComposingDelta) { FlValueEq(commit)), ::testing::_, ::testing::_, ::testing::_)); - g_signal_emit_by_name(context, "commit", "engine", nullptr); + g_signal_emit_by_name(context, "commit", "Flutter engine", nullptr); // end g_autoptr(FlValue) end = build_list({ @@ -1052,3 +1054,241 @@ TEST(FlTextInputPluginTest, ComposingDelta) { g_signal_emit_by_name(context, "preedit-end", nullptr); } + +TEST(FlTextInputPluginTest, NonComposingDelta) { + ::testing::NiceMock messenger; + ::testing::NiceMock context; + ::testing::NiceMock delegate; + + g_autoptr(FlTextInputPlugin) plugin = + fl_text_input_plugin_new(messenger, context, delegate); + EXPECT_NE(plugin, nullptr); + + // set config + g_autoptr(FlValue) args = build_input_config({ + .client_id = 1, + .enable_delta_model = true, + }); + g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new(); + g_autoptr(GBytes) set_client = fl_method_codec_encode_method_call( + FL_METHOD_CODEC(codec), "TextInput.setClient", args, nullptr); + + g_autoptr(FlValue) null = fl_value_new_null(); + EXPECT_CALL(messenger, fl_binary_messenger_send_response( + ::testing::Eq(messenger), + ::testing::A(), + SuccessResponse(null), ::testing::A())) + .WillOnce(::testing::Return(true)); + + messenger.ReceiveMessage("flutter/textinput", set_client); + + // commit F + g_autoptr(FlValue) commit = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "", + .delta_text = "F", + .delta_start = 0, + .delta_end = 0, + .selection_base = 1, + .selection_extent = 1, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commit)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "F", nullptr); + + // commit l + g_autoptr(FlValue) commitL = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "F", + .delta_text = "l", + .delta_start = 1, + .delta_end = 1, + .selection_base = 2, + .selection_extent = 2, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commitL)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "l", nullptr); + + // commit u + g_autoptr(FlValue) commitU = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "Fl", + .delta_text = "u", + .delta_start = 2, + .delta_end = 2, + .selection_base = 3, + .selection_extent = 3, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commitU)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "u", nullptr); + + // commit t + g_autoptr(FlValue) commitTa = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "Flu", + .delta_text = "t", + .delta_start = 3, + .delta_end = 3, + .selection_base = 4, + .selection_extent = 4, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commitTa)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "t", nullptr); + + // commit t again + g_autoptr(FlValue) commitTb = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "Flut", + .delta_text = "t", + .delta_start = 4, + .delta_end = 4, + .selection_base = 5, + .selection_extent = 5, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commitTb)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "t", nullptr); + + // commit e + g_autoptr(FlValue) commitE = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "Flutt", + .delta_text = "e", + .delta_start = 5, + .delta_end = 5, + .selection_base = 6, + .selection_extent = 6, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commitE)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "e", nullptr); + + // commit r + g_autoptr(FlValue) commitR = build_list({ + fl_value_new_int(1), // client_id + build_map({{ + "deltas", + build_list({ + build_editing_delta({ + .old_text = "Flutte", + .delta_text = "r", + .delta_start = 6, + .delta_end = 6, + .selection_base = 7, + .selection_extent = 7, + .composing_base = -1, + .composing_extent = -1, + }), + }), + }}), + }); + + EXPECT_CALL(messenger, + fl_binary_messenger_send_on_channel( + ::testing::Eq(messenger), + ::testing::StrEq("flutter/textinput"), + MethodCall("TextInputClient.updateEditingStateWithDeltas", + FlValueEq(commitR)), + ::testing::_, ::testing::_, ::testing::_)); + + g_signal_emit_by_name(context, "commit", "r", nullptr); +} From 2bade18b3a84aa40965ac7ac019141572a4833ba Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 03:52:49 -0700 Subject: [PATCH 11/17] updates --- shell/platform/linux/fl_text_input_plugin.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 3d09b4b5a043b..530deda443729 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -276,6 +276,7 @@ static void im_preedit_changed_cb(FlTextInputPlugin* self) { } priv->text_model->UpdateComposingText(buf); priv->text_model->SetSelection(flutter::TextRange(cursor_offset)); + if (priv->enable_delta_model) { std::string text(buf); flutter::TextEditingDelta delta = flutter::TextEditingDelta( From bedd07c825bf5cd7972773452832f51ff3662624 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 11:06:02 -0700 Subject: [PATCH 12/17] Address reviewer comments --- shell/platform/linux/fl_text_input_plugin.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 530deda443729..2b8827b346b46 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -295,7 +295,7 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { flutter::TextRange composing_before_change = priv->text_model->composing_range(); flutter::TextRange selection_before_change = priv->text_model->selection(); - gboolean wasComposing = priv->text_model->composing(); + gboolean was_composing = priv->text_model->composing(); priv->text_model->AddText(text); if (priv->text_model->composing()) { @@ -303,16 +303,10 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { } if (priv->enable_delta_model) { - flutter::TextEditingDelta* delta; - if (wasComposing) { - delta = new flutter::TextEditingDelta(text_before_change, - composing_before_change, text); - } else { - delta = new flutter::TextEditingDelta(text_before_change, - selection_before_change, text); - } + flutter::TextRange replace_range = was_composing ? composing_before_change : selection_before_range; + std::unique_ptr delta = + std::make_unique(text_before_change, replace_range, text); update_editing_state_with_delta(self, delta); - delete delta; } else { update_editing_state(self); } @@ -322,11 +316,13 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { static void im_preedit_end_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); + flutter::TextRange composing_before_change = + priv->text_model->composing_range(); std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = flutter::TextEditingDelta( - text_before_change, flutter::TextRange(-1, -1), + text_before_change, composing_before_change, priv->text_model->GetText()); update_editing_state_with_delta(self, &delta); } else { From 3d2f51c1d993328ad98795b1fabb6f141c060920 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 11:07:26 -0700 Subject: [PATCH 13/17] patch --- shell/platform/linux/fl_text_input_plugin.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 2b8827b346b46..070ea66f02ee5 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -303,9 +303,11 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { } if (priv->enable_delta_model) { - flutter::TextRange replace_range = was_composing ? composing_before_change : selection_before_range; + flutter::TextRange replace_range = + was_composing ? composing_before_change : selection_before_range; std::unique_ptr delta = - std::make_unique(text_before_change, replace_range, text); + std::make_unique(text_before_change, + replace_range, text); update_editing_state_with_delta(self, delta); } else { update_editing_state(self); @@ -321,9 +323,9 @@ static void im_preedit_end_cb(FlTextInputPlugin* self) { std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); if (priv->enable_delta_model) { - flutter::TextEditingDelta delta = flutter::TextEditingDelta( - text_before_change, composing_before_change, - priv->text_model->GetText()); + flutter::TextEditingDelta delta = + flutter::TextEditingDelta(text_before_change, composing_before_change, + priv->text_model->GetText()); update_editing_state_with_delta(self, &delta); } else { update_editing_state(self); From 1317a3a5eb9eea40db35e3c724edc855be65174c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 8 Jun 2023 11:35:25 -0700 Subject: [PATCH 14/17] Update shell/platform/linux/fl_text_input_plugin.cc --- shell/platform/linux/fl_text_input_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 070ea66f02ee5..11c7558e4e9e2 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -304,7 +304,7 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { if (priv->enable_delta_model) { flutter::TextRange replace_range = - was_composing ? composing_before_change : selection_before_range; + was_composing ? composing_before_change : selection_before_change; std::unique_ptr delta = std::make_unique(text_before_change, replace_range, text); From 73fd1ed7dfc32f622955bc52e4afc24a076b52a6 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 12:09:15 -0700 Subject: [PATCH 15/17] pass raw pointer and not unique ptr --- shell/platform/linux/fl_text_input_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 11c7558e4e9e2..9c01ab7583ee2 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -308,7 +308,7 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { std::unique_ptr delta = std::make_unique(text_before_change, replace_range, text); - update_editing_state_with_delta(self, delta); + update_editing_state_with_delta(self, delta.get()); } else { update_editing_state(self); } From bd1e88edfc5b825a9116485c6c95ea6112e5f341 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 12:47:34 -0700 Subject: [PATCH 16/17] revert preedit-end using composing_before_change --- shell/platform/linux/fl_text_input_plugin.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 9c01ab7583ee2..45be481efecc7 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -318,13 +318,11 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { static void im_preedit_end_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); - flutter::TextRange composing_before_change = - priv->text_model->composing_range(); std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = - flutter::TextEditingDelta(text_before_change, composing_before_change, + flutter::TextEditingDelta(text_before_change, flutter::TextRange(-1,-1), priv->text_model->GetText()); update_editing_state_with_delta(self, &delta); } else { From 5c3f14a376187b67b797ea59b8fd74cfe827199e Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 8 Jun 2023 12:58:58 -0700 Subject: [PATCH 17/17] updates --- shell/platform/linux/fl_text_input_plugin.cc | 4 +--- shell/platform/linux/fl_text_input_plugin_test.cc | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/shell/platform/linux/fl_text_input_plugin.cc b/shell/platform/linux/fl_text_input_plugin.cc index 45be481efecc7..bb32331d27a01 100644 --- a/shell/platform/linux/fl_text_input_plugin.cc +++ b/shell/platform/linux/fl_text_input_plugin.cc @@ -318,12 +318,10 @@ static void im_commit_cb(FlTextInputPlugin* self, const gchar* text) { static void im_preedit_end_cb(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); - std::string text_before_change = priv->text_model->GetText(); priv->text_model->EndComposing(); if (priv->enable_delta_model) { flutter::TextEditingDelta delta = - flutter::TextEditingDelta(text_before_change, flutter::TextRange(-1,-1), - priv->text_model->GetText()); + flutter::TextEditingDelta(priv->text_model->GetText()); update_editing_state_with_delta(self, &delta); } else { update_editing_state(self); diff --git a/shell/platform/linux/fl_text_input_plugin_test.cc b/shell/platform/linux/fl_text_input_plugin_test.cc index 08472b8d7d6c3..d01fa7642f8ba 100644 --- a/shell/platform/linux/fl_text_input_plugin_test.cc +++ b/shell/platform/linux/fl_text_input_plugin_test.cc @@ -1036,7 +1036,6 @@ TEST(FlTextInputPluginTest, ComposingDelta) { build_list({ build_editing_delta({ .old_text = "Flutter engine", - .delta_text = "Flutter engine", .selection_base = 14, .selection_extent = 14, }),