diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp index 7c36dbefe76..e68cffc3cfb 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp @@ -910,7 +910,8 @@ void RichEditorPattern::SetGestureOptions(UserGestureOptions options, RefPtrSetLongPressEvent(std::move(options.onLongPress))); } -int32_t RichEditorPattern::AddImageSpan(ImageSpanOptions options, bool isPaste, int32_t index, bool updateCaret) +int32_t RichEditorPattern::AddImageSpan(const ImageSpanOptions& options, bool isPaste, int32_t index, + bool updateCaret) { auto host = GetHost(); CHECK_NULL_RETURN(host, -1); @@ -922,7 +923,6 @@ int32_t RichEditorPattern::AddImageSpan(ImageSpanOptions options, bool isPaste, auto pattern = imageNode->GetPattern(); CHECK_NULL_RETURN(pattern, -1); pattern->SetSyncLoad(true); - HandlePreviewWhenAddSpan(options.offset); int32_t insertIndex = options.offset.value_or(GetTextContentLength()); insertIndex = std::min(insertIndex, GetTextContentLength()); RichEditorChangeValue changeValue; @@ -1021,7 +1021,7 @@ void RichEditorPattern::OnDetachFromFrameNode(FrameNode* node) context->RemoveWindowSizeChangeCallback(frameId_); } -int32_t RichEditorPattern::AddPlaceholderSpan(const RefPtr& customNode, SpanOptionBase options) +int32_t RichEditorPattern::AddPlaceholderSpan(const RefPtr& customNode, const SpanOptionBase& options) { CHECK_NULL_RETURN(customNode, 0); auto host = GetHost(); @@ -1035,7 +1035,6 @@ int32_t RichEditorPattern::AddPlaceholderSpan(const RefPtr& customNode, SetSelfAndChildDraggableFalse(customNode); auto focusHub = placeholderSpanNode->GetOrCreateFocusHub(); focusHub->SetFocusable(false); - HandlePreviewWhenAddSpan(options.offset); int32_t insertIndex = options.offset.value_or(GetTextContentLength()); int32_t spanIndex = TextSpanSplit(insertIndex); if (spanIndex == -1) { @@ -1081,20 +1080,6 @@ void RichEditorPattern::SetSelfAndChildDraggableFalse(const RefPtr& cust } } -void RichEditorPattern::HandlePreviewWhenAddSpan(std::optional& offset) -{ - CHECK_NULL_VOID(IsPreviewTextInputting()); - if (offset && offset.value() > previewTextRecord_.startOffset) { - auto& targetIndex = offset.value(); - auto diff = std::min(targetIndex, previewTextRecord_.endOffset) - previewTextRecord_.startOffset; - TAG_LOGI(AceLogTag::ACE_RICH_TEXT, - "addSpan, adjust index, preview range=[%{public}d,%{public}d], index=%{public}d diff=%{public}d", - previewTextRecord_.startOffset, previewTextRecord_.endOffset, targetIndex, diff); - targetIndex -= diff; - } - NotifyExitTextPreview(); -} - int32_t RichEditorPattern::AddTextSpan(TextSpanOptions options, bool isPaste, int32_t index) { TAG_LOGD(AceLogTag::ACE_RICH_TEXT, "options=%{private}s", options.ToString().c_str()); @@ -1194,11 +1179,11 @@ void RichEditorPattern::UpdateSpanNode(RefPtr spanNode, const TextSpan spanNode->UpdateFontFeature(textStyle.GetFontFeatures()); } -int32_t RichEditorPattern::AddSymbolSpan(SymbolSpanOptions options, bool isPaste, int32_t index) +int32_t RichEditorPattern::AddSymbolSpan(const SymbolSpanOptions& options, bool isPaste, int32_t index) { 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); - HandlePreviewWhenAddSpan(options.offset); + RichEditorChangeValue changeValue; CHECK_NULL_RETURN(BeforeAddSymbol(changeValue, options), -1); OperationRecord record; diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h index c39aa52bb22..1c7b415ec2b 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h @@ -529,15 +529,15 @@ public: std::vector GetParagraphInfo(int32_t start, int32_t end); void SetTypingStyle(std::optional typingStyle, std::optional textStyle); std::optional GetTypingStyle(); - void HandlePreviewWhenAddSpan(std::optional& offset); - int32_t AddImageSpan(ImageSpanOptions options, bool isPaste = false, int32_t index = -1, bool updateCaret = true); + int32_t AddImageSpan(const ImageSpanOptions& options, bool isPaste = false, int32_t index = -1, + bool updateCaret = true); int32_t AddTextSpan(TextSpanOptions options, bool isPaste = false, int32_t index = -1); int32_t AddTextSpanOperation(const TextSpanOptions& options, bool isPaste = false, int32_t index = -1, bool needLeadingMargin = false, bool updateCaretPosition = true); - int32_t AddSymbolSpan(SymbolSpanOptions options, bool isPaste = false, int32_t index = -1); + int32_t AddSymbolSpan(const SymbolSpanOptions& options, bool isPaste = false, int32_t index = -1); int32_t AddSymbolSpanOperation(const SymbolSpanOptions& options, bool isPaste = false, int32_t index = -1); void AddSpanItem(const RefPtr& item, int32_t offset); - int32_t AddPlaceholderSpan(const RefPtr& customNode, SpanOptionBase options); + int32_t AddPlaceholderSpan(const RefPtr& customNode, const SpanOptionBase& options); void HandleSelectOverlayWithOptions(const SelectionOptions& options); void SetSelection(int32_t start, int32_t end, const std::optional& options = std::nullopt, bool isForward = false) override;