From 2e1ed7517f21660033580314ae2e7770e7c3e3a0 Mon Sep 17 00:00:00 2001 From: zourongchun Date: Sun, 24 Nov 2024 12:58:38 +0800 Subject: [PATCH 1/2] Revert "Sets the mime type for different data types" This reverts commit 54e24cdb66f58d189b80629acb5b4f2e492eaed5. --- ui/base/clipboard/ohos/clipboard_ohos.cc | 31 ++++++++++++------------ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/ui/base/clipboard/ohos/clipboard_ohos.cc b/ui/base/clipboard/ohos/clipboard_ohos.cc index cf70e39616..550e9b89d4 100644 --- a/ui/base/clipboard/ohos/clipboard_ohos.cc +++ b/ui/base/clipboard/ohos/clipboard_ohos.cc @@ -373,42 +373,41 @@ class ClipboardOHOSInternal { #if defined(OHOS_CLIPBOARD) CopyOptionMode copy_option = currentData->copy_option(); #endif // defined(OHOS_CLIPBOARD) + std::shared_ptr record = + PasteDataRecordAdapter::NewRecord("text/html"); if (HasFormat(ClipboardInternalFormat::kHtml)) { - auto html = std::make_shared(currentData->markup_data()); - auto text = HasFormat(ClipboardInternalFormat::kText) - ? std::make_shared(currentData->text()) - : nullptr; - std::shared_ptr record = - PasteDataRecordAdapter::NewRecord("text/html", html, text); - LOG(INFO) << "set html " << (text ? "and text " : "") << "to record success"; - result_vector.push_back(record); - } else if (HasFormat(ClipboardInternalFormat::kText)) { - std::shared_ptr record = - PasteDataRecordAdapter::NewRecord("text/plain"); - auto text = std::make_shared(currentData->text()); + std::shared_ptr html = + std::make_shared(currentData->markup_data()); + if (record->SetHtmlText(html)) { + LOG(INFO) << "set html to record success"; + } else { + LOG(ERROR) << "set html to record failed"; + } + } + + if (HasFormat(ClipboardInternalFormat::kText)) { + std::shared_ptr text = + std::make_shared(currentData->text()); if (record->SetPlainText(text)) { LOG(INFO) << "set text to record success"; - result_vector.push_back(record); } else { LOG(ERROR) << "set text to record failed"; } } if (HasFormat(ClipboardInternalFormat::kPng)) { - std::shared_ptr record = - PasteDataRecordAdapter::NewRecord("pixelMap"); auto bitmap = currentData->GetBitmapIfPngNotEncoded(); if (bitmap.has_value()) { auto bitmap_record = WriteBitmapToClipboard(bitmap.value()); if (record->SetImgData(bitmap_record)) { LOG(INFO) << "set image to record success"; - result_vector.push_back(record); } else { LOG(ERROR) << "set image to record failed"; } } } + result_vector.push_back(record); OhosAdapterHelper::GetInstance().GetPasteBoard().SetPasteData(result_vector #if defined(OHOS_CLIPBOARD) , -- Gitee From 0c9611779313f80ac289d31bd048e873fe2d779c Mon Sep 17 00:00:00 2001 From: zourongchun Date: Sun, 24 Nov 2024 13:01:48 +0800 Subject: [PATCH 2/2] fix paste Signed-off-by: zourongchun --- ui/base/clipboard/ohos/clipboard_ohos.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/base/clipboard/ohos/clipboard_ohos.cc b/ui/base/clipboard/ohos/clipboard_ohos.cc index 550e9b89d4..723e0e104a 100644 --- a/ui/base/clipboard/ohos/clipboard_ohos.cc +++ b/ui/base/clipboard/ohos/clipboard_ohos.cc @@ -373,9 +373,9 @@ class ClipboardOHOSInternal { #if defined(OHOS_CLIPBOARD) CopyOptionMode copy_option = currentData->copy_option(); #endif // defined(OHOS_CLIPBOARD) - std::shared_ptr record = - PasteDataRecordAdapter::NewRecord("text/html"); + std::shared_ptr record; if (HasFormat(ClipboardInternalFormat::kHtml)) { + record = PasteDataRecordAdapter::NewRecord("text/html"); std::shared_ptr html = std::make_shared(currentData->markup_data()); if (record->SetHtmlText(html)) { @@ -383,6 +383,8 @@ class ClipboardOHOSInternal { } else { LOG(ERROR) << "set html to record failed"; } + } else { + record = PasteDataRecordAdapter::NewRecord("text/plain"); } if (HasFormat(ClipboardInternalFormat::kText)) { -- Gitee