mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
!37107 【RichEditor】完善onWillChangeTDD
Merge pull request !37107 from xuyue/onwillTDD
This commit is contained in:
commit
d96fa0f659
@ -886,13 +886,18 @@ int32_t RichEditorPattern::AddSymbolSpan(const SymbolSpanOptions& options, bool
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_RICH_TEXT, "options=%{public}s", options.ToString().c_str());
|
||||
TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "isPaste=%{public}d, index=%{public}d", isPaste, index);
|
||||
|
||||
RichEditorChangeValue changeValue;
|
||||
CHECK_NULL_RETURN(BeforeAddSymbol(changeValue, options), -1);
|
||||
OperationRecord record;
|
||||
record.beforeCaretPosition = options.offset.value_or(static_cast<int32_t>(GetTextContentLength()));
|
||||
record.addText = " ";
|
||||
ClearRedoOperationRecords();
|
||||
record.afterCaretPosition = record.beforeCaretPosition + 1;
|
||||
AddOperationRecord(record);
|
||||
return AddSymbolSpanOperation(options, isPaste, index);
|
||||
auto ret = AddSymbolSpanOperation(options, isPaste, index);
|
||||
AfterAddSymbol(changeValue);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t RichEditorPattern::AddSymbolSpanOperation(const SymbolSpanOptions& options, bool isPaste, int32_t index)
|
||||
|
@ -75,8 +75,8 @@ struct SymbolSpanStyle {
|
||||
std::string symbolColor;
|
||||
FONT_FEATURES_LIST fontFeature;
|
||||
int32_t fontWeight = 0;
|
||||
uint32_t renderingStrategy;
|
||||
uint32_t effectStrategy;
|
||||
int32_t renderingStrategy = 0;
|
||||
int32_t effectStrategy = 0;
|
||||
|
||||
SymbolSpanStyle() {}
|
||||
SymbolSpanStyle(const TextStyle& style)
|
||||
@ -97,6 +97,25 @@ struct SymbolSpanStyle {
|
||||
renderingStrategy = style.GetRenderStrategy();
|
||||
effectStrategy = style.GetEffectStrategy();
|
||||
}
|
||||
|
||||
bool operator==(const SymbolSpanStyle& rhs) const
|
||||
{
|
||||
return fontSize == rhs.fontSize
|
||||
&& lineHeight == rhs.lineHeight
|
||||
&& letterSpacing == rhs.letterSpacing
|
||||
&& lineSpacing == rhs.lineSpacing
|
||||
&& symbolColor == rhs.symbolColor
|
||||
&& fontFeature == rhs.fontFeature
|
||||
&& fontFeature == rhs.fontFeature
|
||||
&& fontWeight == rhs.fontWeight
|
||||
&& renderingStrategy == rhs.renderingStrategy
|
||||
&& effectStrategy == rhs.effectStrategy;
|
||||
}
|
||||
|
||||
bool operator!=(const SymbolSpanStyle& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
struct TextStyleResult {
|
||||
|
@ -767,6 +767,147 @@ HWTEST_F(RichEditorChangeCallbackTestNg, ChangeTextCallbackTest012, TestSize.Lev
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ChangeTextCallbackTest013
|
||||
* @tc.desc: test for callback onWillchange/onDidChange, add symbol span
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RichEditorChangeCallbackTestNg, ChangeTextCallbackTest013, TestSize.Level1)
|
||||
{
|
||||
RichEditorModelNG richEditorModel;
|
||||
richEditorModel.Create();
|
||||
auto host = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(host, nullptr);
|
||||
auto richEditorPattern = host->GetPattern<RichEditorPattern>();
|
||||
ASSERT_NE(richEditorPattern, nullptr);
|
||||
InitContentChangeCallback(richEditorModel);
|
||||
|
||||
richEditorPattern->AddSymbolSpan(SYMBOL_SPAN_OPTIONS_1);
|
||||
|
||||
// check onWill rangeBefore
|
||||
EXPECT_EQ(onWillRangeBefore.start, 0);
|
||||
EXPECT_EQ(onWillRangeBefore.end, 0);
|
||||
|
||||
// check onWill span info
|
||||
ASSERT_EQ(onWillReplacedSpans.size(), 0);
|
||||
ASSERT_EQ(onWillReplacedImageSpans.size(), 0);
|
||||
ASSERT_EQ(onWillReplacedSymbolSpans.size(), 1);
|
||||
|
||||
auto& spanResult = onWillReplacedSymbolSpans[0];
|
||||
EXPECT_EQ(spanResult.spanIndex_, 0);
|
||||
EXPECT_EQ(spanResult.offsetInSpan_, 0);
|
||||
EXPECT_EQ(spanResult.eraseLength_, 2);
|
||||
EXPECT_EQ(spanResult.spanRangeStart_, 0);
|
||||
EXPECT_EQ(spanResult.spanRangeEnd_, 2);
|
||||
EXPECT_EQ(spanResult.spanType_, SpanResultType::SYMBOL);
|
||||
EXPECT_EQ(spanResult.symbolSpanStyle_, SymbolSpanStyle(TEXT_STYLE_1));
|
||||
|
||||
// check onDid rangeBefore
|
||||
EXPECT_EQ(onDidRangeBefore, onWillRangeBefore);
|
||||
|
||||
// check onDid rangeAfter
|
||||
EXPECT_EQ(onDidRangeAfter.start, 0);
|
||||
EXPECT_EQ(onDidRangeAfter.end, 2);
|
||||
while (!ViewStackProcessor::GetInstance()->elementsStack_.empty()) {
|
||||
ViewStackProcessor::GetInstance()->elementsStack_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ChangeTextCallbackTest014
|
||||
* @tc.desc: test for callback onWillchange/onDidChange, add symbol span
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RichEditorChangeCallbackTestNg, ChangeTextCallbackTest014, TestSize.Level1)
|
||||
{
|
||||
RichEditorModelNG richEditorModel;
|
||||
richEditorModel.Create();
|
||||
auto host = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(host, nullptr);
|
||||
auto richEditorPattern = host->GetPattern<RichEditorPattern>();
|
||||
ASSERT_NE(richEditorPattern, nullptr);
|
||||
InitContentChangeCallback(richEditorModel);
|
||||
|
||||
richEditorPattern->AddTextSpan(TEXT_SPAN_OPTIONS_1);
|
||||
richEditorPattern->AddSymbolSpan(SYMBOL_SPAN_OPTIONS_1);
|
||||
|
||||
// check onWill rangeBefore
|
||||
EXPECT_EQ(onWillRangeBefore.start, 6);
|
||||
EXPECT_EQ(onWillRangeBefore.end, 6);
|
||||
|
||||
// check onWill span info
|
||||
ASSERT_EQ(onWillReplacedSpans.size(), 0);
|
||||
ASSERT_EQ(onWillReplacedImageSpans.size(), 0);
|
||||
ASSERT_EQ(onWillReplacedSymbolSpans.size(), 1);
|
||||
|
||||
auto& spanResult = onWillReplacedSymbolSpans[0];
|
||||
EXPECT_EQ(spanResult.spanIndex_, 1);
|
||||
EXPECT_EQ(spanResult.offsetInSpan_, 0);
|
||||
EXPECT_EQ(spanResult.eraseLength_, 2);
|
||||
EXPECT_EQ(spanResult.spanRangeStart_, 6);
|
||||
EXPECT_EQ(spanResult.spanRangeEnd_, 8);
|
||||
EXPECT_EQ(spanResult.spanType_, SpanResultType::SYMBOL);
|
||||
EXPECT_EQ(spanResult.symbolSpanStyle_, SymbolSpanStyle(TEXT_STYLE_1));
|
||||
|
||||
// check onDid rangeBefore
|
||||
EXPECT_EQ(onDidRangeBefore, onWillRangeBefore);
|
||||
|
||||
// check onDid rangeAfter
|
||||
EXPECT_EQ(onDidRangeAfter.start, 6);
|
||||
EXPECT_EQ(onDidRangeAfter.end, 8);
|
||||
while (!ViewStackProcessor::GetInstance()->elementsStack_.empty()) {
|
||||
ViewStackProcessor::GetInstance()->elementsStack_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ChangeTextCallbackTest015
|
||||
* @tc.desc: test for callback onWillchange/onDidChange, add symbol span
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RichEditorChangeCallbackTestNg, ChangeTextCallbackTest015, TestSize.Level1)
|
||||
{
|
||||
RichEditorModelNG richEditorModel;
|
||||
richEditorModel.Create();
|
||||
auto host = ViewStackProcessor::GetInstance()->GetMainFrameNode();
|
||||
ASSERT_NE(host, nullptr);
|
||||
auto richEditorPattern = host->GetPattern<RichEditorPattern>();
|
||||
ASSERT_NE(richEditorPattern, nullptr);
|
||||
InitContentChangeCallback(richEditorModel);
|
||||
|
||||
richEditorPattern->AddTextSpan(TEXT_SPAN_OPTIONS_1); // add hello1
|
||||
auto options = SYMBOL_SPAN_OPTIONS_1;
|
||||
options.offset = 3;
|
||||
richEditorPattern->AddSymbolSpan(options);
|
||||
|
||||
// check onWill rangeBefore
|
||||
EXPECT_EQ(onWillRangeBefore.start, 3);
|
||||
EXPECT_EQ(onWillRangeBefore.end, 3);
|
||||
|
||||
// check onWill span info
|
||||
ASSERT_EQ(onWillReplacedSpans.size(), 0);
|
||||
ASSERT_EQ(onWillReplacedImageSpans.size(), 0);
|
||||
ASSERT_EQ(onWillReplacedSymbolSpans.size(), 1);
|
||||
|
||||
auto& spanResult = onWillReplacedSymbolSpans[0];
|
||||
EXPECT_EQ(spanResult.spanIndex_, 1);
|
||||
EXPECT_EQ(spanResult.offsetInSpan_, 0);
|
||||
EXPECT_EQ(spanResult.eraseLength_, 2);
|
||||
EXPECT_EQ(spanResult.spanRangeStart_, 3);
|
||||
EXPECT_EQ(spanResult.spanRangeEnd_, 5);
|
||||
EXPECT_EQ(spanResult.spanType_, SpanResultType::SYMBOL);
|
||||
EXPECT_EQ(spanResult.symbolSpanStyle_, SymbolSpanStyle(TEXT_STYLE_1));
|
||||
|
||||
// check onDid rangeBefore
|
||||
EXPECT_EQ(onDidRangeBefore, onWillRangeBefore);
|
||||
|
||||
// check onDid rangeAfter
|
||||
EXPECT_EQ(onDidRangeAfter.start, 3);
|
||||
EXPECT_EQ(onDidRangeAfter.end, 5);
|
||||
while (!ViewStackProcessor::GetInstance()->elementsStack_.empty()) {
|
||||
ViewStackProcessor::GetInstance()->elementsStack_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleOnEditChanged001
|
||||
|
@ -168,6 +168,12 @@ const ImageSpanOptions IMAGE_SPAN_OPTIONS_1 = {
|
||||
.imagePixelMap = std::nullopt,
|
||||
.imageAttribute = IMAGE_SPAN_ATTRIBUTE_1
|
||||
};
|
||||
const SymbolSpanOptions SYMBOL_SPAN_OPTIONS_1 = {
|
||||
.offset = std::nullopt,
|
||||
.symbolId = 0,
|
||||
.style = TEXT_STYLE_1,
|
||||
.resourceObject = nullptr
|
||||
};
|
||||
} // namespace
|
||||
|
||||
struct TestCursorItem {
|
||||
|
Loading…
Reference in New Issue
Block a user