diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index 4225c6e8d8ecfcb9293c95b9c76e5211019ccff1..c80c434943c45bc99575a0fc2fc0d69be62e91fc 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -5950,6 +5950,20 @@ void TextFieldPattern::UpdateEditingValue(const std::shared_ptrselection.baseOffset -= deleteSize; } } +#ifdef CROSS_PLATFORM + if (value->isDelete) { + HandleOnDelete(true); + return; + } else { +#ifdef ANDROID_PLATFORM + if (value->appendText.empty()) { + return; + } +#endif + InsertValue(UtfUtils::Str8DebugToStr16(value->appendText), true); + return; + } +#endif #endif UpdateEditingValueToRecord(); contentController_->SetTextValue(result); diff --git a/test/unittest/core/pattern/text_input/text_field_pattern_testnine.cpp b/test/unittest/core/pattern/text_input/text_field_pattern_testnine.cpp index ce9bd0e21b70f267d2248b43d3860c954d71ec66..3da30dc57606452ebddc77c3deb3e08f1d25ed69 100644 --- a/test/unittest/core/pattern/text_input/text_field_pattern_testnine.cpp +++ b/test/unittest/core/pattern/text_input/text_field_pattern_testnine.cpp @@ -1206,4 +1206,32 @@ HWTEST_F(TextFieldPatternTestNine, GetMaxIndent, TestSize.Level0) width = textFieldLayoutAlgorithm->GetMaxIndent(&layoutWrapper, std::numeric_limits::infinity()); EXPECT_EQ(width, 200.0f); } + +/** + * @tc.name: UpdateEditingValue001 + * @tc.desc: test UpdateEditingValue + * @tc.type: FUNC + */ +HWTEST_F(TextFieldPatternTestNine, UpdateEditingValue001, TestSize.Level0) +{ + /** + * @tc.steps: step1. Create Text filed node with set maxLength 10 + * @tc.expected: maxLength is 10 + */ + CreateTextField(DEFAULT_TEXT, "", [](TextFieldModelNG model) { + model.SetMaxLength(10); + }); + TextEditingValue value; + TextSelection selection; + value.text = "12345678901234567890"; + selection.baseOffset = value.text.length(); + value.selection = selection; + + /** + * @tc.step: step2. Call UpdateEditingValue + */ + pattern_->UpdateEditingValue(std::make_shared(value)); + FlushLayoutTask(frameNode_); + EXPECT_EQ(pattern_->GetTextValue().length(), 10); +} } // namespace OHOS::Ace::NG \ No newline at end of file