From 634d879df12b8c6d9c1e375982b8d3a1c6f2f694 Mon Sep 17 00:00:00 2001 From: fan_pan Date: Tue, 23 Jul 2024 21:45:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DcopyOption=E4=B8=BANone?= =?UTF-8?q?=E6=97=B6AI=E8=8F=9C=E5=8D=95=E7=9A=84=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E9=A1=B9=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fan_pan Change-Id: I3a9a5412cc55ce13aab326f122e1db829e45a2dc --- adapter/ohos/osal/data_detector_adapter.cpp | 3 +++ .../core/common/ai/data_detector_adapter.h | 1 + .../rich_editor/rich_editor_pattern.cpp | 6 ++--- .../pattern/text/text_pattern.cpp | 22 ++++++++++++++----- .../components_ng/pattern/text/text_pattern.h | 1 + .../ace/ai/data_detector_interface.h | 1 + 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/adapter/ohos/osal/data_detector_adapter.cpp b/adapter/ohos/osal/data_detector_adapter.cpp index c9ce126191e..3171e750009 100644 --- a/adapter/ohos/osal/data_detector_adapter.cpp +++ b/adapter/ohos/osal/data_detector_adapter.cpp @@ -105,6 +105,8 @@ void DataDetectorAdapter::OnClickAIMenuOption(const AISpan& aiSpan, CHECK_NULL_VOID(runtimeContext); auto token = runtimeContext->GetToken(); auto bundleName = runtimeContext->GetBundleName(); + + hasClickedMenuOption_ = true; if (onClickMenu_ && menuOption.first == std::string(COPY_ACTION)) { onClickMenu_(std::string(COPY_ACTION)); } else if (onClickMenu_ && menuOption.first == std::string(SELECT_ACTION)) { @@ -120,6 +122,7 @@ void DataDetectorAdapter::OnClickAIMenuOption(const AISpan& aiSpan, } else { TAG_LOGW(AceLogTag::ACE_TEXT, "No matching menu option"); } + hasClickedMenuOption_ = false; } void DataDetectorAdapter::ResponseBestMatchItem(const AISpan& aiSpan) diff --git a/frameworks/core/common/ai/data_detector_adapter.h b/frameworks/core/common/ai/data_detector_adapter.h index 23976a538a1..95e28429405 100644 --- a/frameworks/core/common/ai/data_detector_adapter.h +++ b/frameworks/core/common/ai/data_detector_adapter.h @@ -97,6 +97,7 @@ private: bool hasClickedAISpan_ = false; bool pressedByLeftMouse_ = false; bool typeChanged_ = false; + bool hasClickedMenuOption_ = false; AISpan clickedAISpan_; std::string textDetectTypes_; std::string textForAI_; 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 0ae0dca5447..93a518caf3c 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 @@ -6270,7 +6270,7 @@ void RichEditorPattern::HandleOnCopyStyledString() subSpanString->EncodeTlv(tlvData); clipboard_->AddSpanStringRecord(pasteData, tlvData); clipboard_->AddTextRecord(pasteData, subSpanString->GetString()); - clipboard_->SetData(pasteData, copyOption_); + clipboard_->SetData(pasteData, HandleOnCopyOptions()); } void RichEditorPattern::OnCopyOperation(bool isUsingExternalKeyboard) @@ -6310,7 +6310,7 @@ void RichEditorPattern::OnCopyOperation(bool isUsingExternalKeyboard) for (auto resultObj = copyResultObjects.rbegin(); resultObj != copyResultObjects.rend(); ++resultObj) { resultProcessor(*resultObj); } - clipboard_->SetData(pasteData, copyOption_); + clipboard_->SetData(pasteData, HandleOnCopyOptions()); } void RichEditorPattern::HandleOnCopy(bool isUsingExternalKeyboard) @@ -6318,7 +6318,7 @@ void RichEditorPattern::HandleOnCopy(bool isUsingExternalKeyboard) CHECK_NULL_VOID(clipboard_); TAG_LOGD(AceLogTag::ACE_RICH_TEXT, "isUsingExternalKeyboard=%{public}d, copyOption=%{public}d", isUsingExternalKeyboard, copyOption_); - if (copyOption_ == CopyOptions::None) { + if (HandleOnCopyOptions() == CopyOptions::None) { return; } auto host = GetHost(); diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.cpp b/frameworks/core/components_ng/pattern/text/text_pattern.cpp index 1aaa50b03af..2a9a6a59a43 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text/text_pattern.cpp @@ -526,6 +526,14 @@ std::string TextPattern::GetSelectedText(int32_t start, int32_t end) const return value; } +CopyOptions TextPattern::HandleOnCopyOptions() +{ + if (copyOption_ == CopyOptions::None && dataDetectorAdapter_->hasClickedMenuOption_) { + return CopyOptions::Local; + } + return copyOption_; +} + void TextPattern::HandleOnCopy() { CHECK_NULL_VOID(clipboard_); @@ -534,11 +542,11 @@ void TextPattern::HandleOnCopy() return; } auto value = GetSelectedText(textSelector_.GetTextStart(), textSelector_.GetTextEnd()); - if (IsSelectableAndCopy()) { + if (IsSelectableAndCopy() || dataDetectorAdapter_->hasClickedMenuOption_) { if (isSpanStringMode_ && !externalParagraph_) { HandleOnCopySpanString(); } else if (!value.empty()) { - clipboard_->SetData(value, copyOption_); + clipboard_->SetData(value, HandleOnCopyOptions()); } } HiddenMenu(); @@ -558,7 +566,7 @@ void TextPattern::HandleOnCopySpanString() std::vector tlvData; subSpanString->EncodeTlv(tlvData); clipboard_->AddSpanStringRecord(pasteData, tlvData); - clipboard_->SetData(pasteData, copyOption_); + clipboard_->SetData(pasteData, HandleOnCopyOptions()); } void TextPattern::HiddenMenu() @@ -880,9 +888,6 @@ void TextPattern::SetOnClickMenu(const AISpan& aiSpan, const CalculateHandleFunc const std::string& action) { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - if (!(pattern->IsSelectableAndCopy())) { - return; - } pattern->CloseSelectOverlay(); pattern->HandleSelectionChange(aiSpan.start, aiSpan.end); if (action == std::string(COPY_ACTION)) { @@ -2202,6 +2207,11 @@ void TextPattern::InitCopyOption() if (onClick_ || IsSelectableAndCopy() || CanStartAITask()) { InitClickEvent(gestureEventHub); if (CanStartAITask()) { + auto context = PipelineContext::GetCurrentContextSafely(); + CHECK_NULL_VOID(context); + if (!clipboard_ && context) { + clipboard_ = ClipboardProxy::GetInstance()->GetClipboard(context->GetTaskExecutor()); + } InitMouseEvent(); } } diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.h b/frameworks/core/components_ng/pattern/text/text_pattern.h index 07c48be2402..8586968d580 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.h +++ b/frameworks/core/components_ng/pattern/text/text_pattern.h @@ -522,6 +522,7 @@ public: bool IsSelectAll(); void HandleOnCopy(); void HandleOnCopySpanString(); + virtual CopyOptions HandleOnCopyOptions(); virtual void HandleOnSelectAll(); void SetTextSelectableMode(TextSelectableMode value); diff --git a/interfaces/inner_api/ace/ai/data_detector_interface.h b/interfaces/inner_api/ace/ai/data_detector_interface.h index 92d106b7360..f15253d8929 100644 --- a/interfaces/inner_api/ace/ai/data_detector_interface.h +++ b/interfaces/inner_api/ace/ai/data_detector_interface.h @@ -18,6 +18,7 @@ #include #include +#include #include #include