From 47fcfe0b215cb81e72ac7e408c62b4f6af4e2711 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 23 Mar 2022 12:02:13 -0700 Subject: [PATCH] Fix entering newline on deltas for windows (flutter/engine#32195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix entering newline * utf8toutf16 * formatting * Address reviews * send *model“ * capture oldtext and selection before newline is added to model * use model vs _active_model_ for consistency * Formatting * updates Co-authored-by: Renzo Olivares --- .../shell/platform/windows/text_input_plugin.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 8e2badaf773..0e8b12fb697 100644 --- a/engine/src/flutter/shell/platform/windows/text_input_plugin.cc +++ b/engine/src/flutter/shell/platform/windows/text_input_plugin.cc @@ -446,8 +446,16 @@ void TextInputPlugin::SendStateUpdateWithDelta(const TextInputModel& model, void TextInputPlugin::EnterPressed(TextInputModel* model) { if (input_type_ == kMultilineInputType) { - model->AddText(std::u16string({u'\n'})); - SendStateUpdate(*model); + std::u16string text_before_change = fml::Utf8ToUtf16(model->GetText()); + TextRange selection_before_change = model->selection(); + model->AddText(u"\n"); + if (enable_delta_model) { + TextEditingDelta delta(text_before_change, selection_before_change, + u"\n"); + SendStateUpdateWithDelta(*model, &delta); + } else { + SendStateUpdate(*model); + } } auto args = std::make_unique(rapidjson::kArrayType); auto& allocator = args->GetAllocator();