From 0d9b02f227382e8e1668cd7164b6ff06b64532a0 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Tue, 22 Mar 2022 12:13:13 -0700 Subject: [PATCH] Linux deltas double free and newline fix (flutter/engine#32168) * Fix double free * Fix entering a newline * Formatting Co-authored-by: Renzo Olivares --- .../flutter/shell/platform/linux/fl_text_input_plugin.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 7b40eb753a..c794437498 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 @@ -216,7 +216,7 @@ static void update_editing_state_with_delta(FlTextInputPlugin* self, g_autoptr(FlValue) deltas = fl_value_new_list(); fl_value_append(deltas, deltaValue); - g_autoptr(FlValue) value = fl_value_new_map(); + FlValue* value = fl_value_new_map(); fl_value_set_string_take(value, "deltas", deltas); fl_value_append(args, value); @@ -629,6 +629,7 @@ static gboolean fl_text_input_plugin_filter_keypress_default( std::string text_before_change = priv->text_model->GetText(); flutter::TextRange selection_before_change = priv->text_model->selection(); + std::string text = priv->text_model->GetText(); // Handle the enter/return key. gboolean do_action = FALSE; @@ -649,6 +650,7 @@ static gboolean fl_text_input_plugin_filter_keypress_default( case GDK_KEY_ISO_Enter: if (priv->input_type == FL_TEXT_INPUT_TYPE_MULTILINE) { priv->text_model->AddCodePoint('\n'); + text = "\n"; changed = TRUE; } do_action = TRUE; @@ -676,8 +678,7 @@ static gboolean fl_text_input_plugin_filter_keypress_default( if (changed) { if (priv->enable_delta_model) { flutter::TextEditingDelta delta = flutter::TextEditingDelta( - text_before_change, priv->text_model->selection(), - priv->text_model->GetText()); + text_before_change, selection_before_change, text); update_editing_state_with_delta(self, &delta); } else { update_editing_state(self);