富文本粘贴bugfix

Signed-off-by: zyx0121 <zhangyingxiang2@huawei.com>
This commit is contained in:
zyx0121 2024-10-19 14:15:18 +08:00
parent f7625b6fe1
commit b8b9cdd271
9 changed files with 28 additions and 19 deletions

View File

@ -572,7 +572,7 @@ void ClipboardImpl::GetDataAsync(const std::function<void(const std::string&, bo
}
void ClipboardImpl::GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback, bool syncMode)
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback, bool syncMode)
{
#ifdef SYSTEM_CLIPBOARD_SUPPORTED
if (!taskExecutor_ || !callback) {
@ -584,7 +584,7 @@ void ClipboardImpl::GetSpanStringData(
}
void ClipboardImpl::GetSpanStringDataHelper(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback, bool syncMode)
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback, bool syncMode)
{
auto task = [callback, weakExecutor = WeakClaim(RawPtr(taskExecutor_)), weak = WeakClaim(this)]() {
auto clip = weak.Upgrade();
@ -598,14 +598,15 @@ void ClipboardImpl::GetSpanStringDataHelper(
CHECK_NULL_VOID(getDataRes);
std::vector<std::vector<uint8_t>> arrays;
std::string text;
clip->ProcessSpanStringData(arrays, pasteData, text);
bool isMultiTypeRecord = false;
clip->ProcessSpanStringData(arrays, pasteData, text, isMultiTypeRecord);
auto textData = pasteData.GetPrimaryText();
if (textData && text.empty()) {
text.append(*textData);
}
auto result = text;
taskExecutor->PostTask(
[callback, arrays, result]() mutable { callback(arrays, result); },
[callback, arrays, result, isMultiTypeRecord]() mutable { callback(arrays, result, isMultiTypeRecord); },
TaskExecutor::TaskType::UI, "ArkUIClipboardGetSpanStringDataCallback");
};
if (syncMode) {
@ -615,8 +616,8 @@ void ClipboardImpl::GetSpanStringDataHelper(
}
}
void ClipboardImpl::ProcessSpanStringData(
std::vector<std::vector<uint8_t>>& arrays, const OHOS::MiscServices::PasteData& pasteData, std::string& text)
void ClipboardImpl::ProcessSpanStringData(std::vector<std::vector<uint8_t>>& arrays,
const OHOS::MiscServices::PasteData& pasteData, std::string& text, bool& isMultiTypeRecord)
{
for (const auto& pasteDataRecord : pasteData.AllRecords()) {
if (pasteDataRecord == nullptr) {
@ -644,6 +645,7 @@ void ClipboardImpl::ProcessSpanStringData(
if (pasteDataRecord->GetPlainText() != nullptr) {
auto textData = pasteDataRecord->GetPlainText();
text.append(*textData);
isMultiTypeRecord = !(*textData).empty() && hasSpanString;
}
}
}

View File

@ -51,7 +51,8 @@ public:
void HasDataType(
const std::function<void(bool hasData)>& callback, const std::vector<std::string>& mimeTypes) override;
void Clear() override;
void GetSpanStringData(const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback,
void GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback,
bool syncMode = false) override;
#ifdef SYSTEM_CLIPBOARD_SUPPORTED
@ -69,10 +70,10 @@ private:
void GetPixelMapDataSync(const std::function<void(const RefPtr<PixelMap>&)>& callback);
void GetPixelMapDataAsync(const std::function<void(const RefPtr<PixelMap>&)>& callback);
void GetSpanStringDataHelper(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback,
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback,
bool syncMode = false);
void ProcessSpanStringData(
std::vector<std::vector<uint8_t>>& arrays, const OHOS::MiscServices::PasteData& pasteData, std::string& text);
void ProcessSpanStringData(std::vector<std::vector<uint8_t>>& arrays,
const OHOS::MiscServices::PasteData& pasteData, std::string& text, bool& isMultiTypeRecord);
const std::string GetMimeType(
std::map<std::string, std::shared_ptr<OHOS::MiscServices::EntryValue>> multiTypeDataMap);
#endif

View File

@ -32,7 +32,7 @@ void ClipboardImpl::GetData(const std::function<void(const std::string&, bool is
const std::function<void(const std::string&, bool isLastRecord)>& urlCallback, bool syncMode)
{}
void ClipboardImpl::GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback, bool syncMode)
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback, bool syncMode)
{}
RefPtr<PasteDataMix> ClipboardImpl::CreatePasteDataMix()

View File

@ -56,7 +56,8 @@ public:
void GetData(const std::function<void(const std::string&, bool isLastRecord)>& textCallback,
const std::function<void(const RefPtr<PixelMap>&, bool isLastRecord)>& pixelMapCallback,
const std::function<void(const std::string&, bool isLastRecord)>& urlCallback, bool syncMode = false) override;
void GetSpanStringData(const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback,
void GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback,
bool syncMode = false) override;
RefPtr<PasteDataMix> CreatePasteDataMix() override;

View File

@ -52,7 +52,7 @@ public:
virtual RefPtr<PasteDataMix> CreatePasteDataMix() = 0;
virtual void Clear() = 0;
virtual void GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback,
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback,
bool syncMode = false) = 0;
protected:

View File

@ -7312,15 +7312,18 @@ void RichEditorPattern::HandleOnPaste()
clipboard_->GetData(pasteCallback);
#else
auto isSpanStringMode = isSpanStringMode_;
auto pasteCallback = [weak = WeakClaim(this), isSpanStringMode](std::vector<std::vector<uint8_t>>& arrs, const std::string& text) {
TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "pasteCallback callback");
auto pasteCallback = [weak = WeakClaim(this), isSpanStringMode](std::vector<std::vector<uint8_t>>& arrs,
const std::string& text, bool& isMulitiTypeRecord) {
TAG_LOGI(AceLogTag::ACE_RICH_TEXT,
"pasteCallback callback, isMulitiTypeRecord : [%{public}d], isSpanStringMode : [%{public}d]",
isMulitiTypeRecord, isSpanStringMode);
auto richEditor = weak.Upgrade();
CHECK_NULL_VOID(richEditor);
std::list<RefPtr<SpanString>> spanStrings;
for (auto arr : arrs) {
spanStrings.push_back(SpanString::DecodeTlv(arr));
}
if (!spanStrings.empty() && isSpanStringMode) {
if (!spanStrings.empty() && !isMulitiTypeRecord) {
for (auto spanString : spanStrings) {
richEditor->AddSpanByPasteData(spanString);
richEditor->RequestKeyboardToEdit();

View File

@ -87,7 +87,7 @@ void MockClipBoard::GetData(const std::function<void(const std::string&, bool is
const std::function<void(const std::string&, bool isLastRecord)>& urlCallback, bool syncMode)
{}
void MockClipBoard::GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback, bool syncMode)
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback, bool syncMode)
{}
RefPtr<PasteDataMix> MockClipBoard::CreatePasteDataMix()

View File

@ -45,7 +45,8 @@ public:
void GetData(const std::function<void(const std::string&, bool isLastRecord)>& textCallback,
const std::function<void(const RefPtr<PixelMap>&, bool isLastRecord)>& pixelMapCallback,
const std::function<void(const std::string&, bool isLastRecord)>& urlCallback, bool syncMode = false) override;
void GetSpanStringData(const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback,
void GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback,
bool syncMode = false) override;
RefPtr<PasteDataMix> CreatePasteDataMix() override;

View File

@ -53,7 +53,8 @@ public:
const std::function<void(const RefPtr<PixelMap>&, bool isLastRecord)>& pixelMapCallback,
const std::function<void(const std::string&, bool isLastRecord)>& urlCallback,
bool syncMode = false) override {};
void GetSpanStringData(const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&)>& callback,
void GetSpanStringData(
const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback,
bool syncMode = false) override {};
RefPtr<PasteDataMix> CreatePasteDataMix()
{