!36563 add onchange when previewRange change

Merge pull request !36563 from 末日拿铁/for_add_onchange
This commit is contained in:
openharmony_ci 2024-06-28 09:18:43 +00:00 committed by Gitee
commit 39924826fc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 8 additions and 2 deletions

View File

@ -139,7 +139,7 @@ public:
void FireOnChange(const std::string& value, TextRange& range)
{
if (lastValue_.has_value() && lastValue_.value() == value) {
if (lastValue_.has_value() && lastValue_.value() == value && lastPreviewRange_ == range) {
return;
}
if (onValueChangeEvent_) {
@ -152,6 +152,7 @@ public:
onChange_(value, range);
}
lastValue_ = value;
lastPreviewRange_ = range;
}
void SetOnContentSizeChange(std::function<void(float, float)>&& func)
@ -364,6 +365,7 @@ public:
private:
std::optional<std::string> lastValue_;
TextRange lastPreviewRange_ {};
OnScrollEvent onScrollEvent_;
OnScrollBeginEvent onScrollBeginEvent_;

View File

@ -160,6 +160,7 @@ public:
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, TextIndent, Dimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP(TextLineStyle, NumberOfLines, int32_t, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Value, std::string, PROPERTY_UPDATE_NORMAL);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PreviewRange, TextRange, PROPERTY_UPDATE_NORMAL);
ACE_DEFINE_PROPERTY_GROUP(PlaceholderFontStyle, FontStyle);
ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(

View File

@ -2753,7 +2753,9 @@ bool TextFieldPattern::FireOnTextChangeEvent()
}
}
auto textCache = layoutProperty->GetValueValue("");
if (textCache == contentController_->GetTextValue()) {
auto rangeCache = layoutProperty->GetPreviewRangeValue({-1, -1});
TextRange curPreviewRange = {GetPreviewTextStart(), GetPreviewTextEnd()};
if (textCache == contentController_->GetTextValue() && rangeCache == curPreviewRange) {
return false;
}
host->OnAccessibilityEvent(AccessibilityEventType::TEXT_CHANGE, textCache, contentController_->GetTextValue());
@ -2803,6 +2805,7 @@ void TextFieldPattern::AddTextFireOnChange()
TextRange range;
range.start = pattern->GetPreviewTextStart();
range.end = pattern->GetPreviewTextEnd();
layoutProperty->UpdatePreviewRange(range);
eventHub->FireOnChange(pattern->GetTextContentController()->GetTextValue(), range);
});
}