修复copyOption为None时AI菜单的复制项不生效的问题

Signed-off-by: fan_pan <fanpan10@huawei.com>
Change-Id: I3a9a5412cc55ce13aab326f122e1db829e45a2dc
This commit is contained in:
fan_pan 2024-07-23 21:45:23 +08:00
parent f8e6a33ae0
commit 634d879df1
6 changed files with 25 additions and 9 deletions

View File

@ -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)

View File

@ -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_;

View File

@ -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();

View File

@ -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<uint8_t> 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();
}
}

View File

@ -522,6 +522,7 @@ public:
bool IsSelectAll();
void HandleOnCopy();
void HandleOnCopySpanString();
virtual CopyOptions HandleOnCopyOptions();
virtual void HandleOnSelectAll();
void SetTextSelectableMode(TextSelectableMode value);

View File

@ -18,6 +18,7 @@
#include <functional>
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>