diff --git a/ui/base/clipboard/ohos/clipboard_ohos.cc b/ui/base/clipboard/ohos/clipboard_ohos.cc index cf70e3961650aec39ba8cc7a15757581e71a0a5c..723e0e104a1487e69ce4911afd62214d630a30d4 100644 --- a/ui/base/clipboard/ohos/clipboard_ohos.cc +++ b/ui/base/clipboard/ohos/clipboard_ohos.cc @@ -373,42 +373,43 @@ class ClipboardOHOSInternal { #if defined(OHOS_CLIPBOARD) CopyOptionMode copy_option = currentData->copy_option(); #endif // defined(OHOS_CLIPBOARD) + std::shared_ptr record; 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()); + record = PasteDataRecordAdapter::NewRecord("text/html"); + 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"; + } + } else { + record = PasteDataRecordAdapter::NewRecord("text/plain"); + } + + 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) ,