diff --git a/sw/qa/extras/uiwriter/data/placeholder-bold.fodt b/sw/qa/extras/uiwriter/data/placeholder-bold.fodt new file mode 100644 index 000000000000..55ecf66df714 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/placeholder-bold.fodt @@ -0,0 +1,114 @@ + + + 2024-08-08T18:32:28.4200828172024-08-08T18:33:51.021911316PT1M27S1ZetaOffice/7.4.8.0.0$Linux_X86_64 LibreOffice_project/ab7057b1137e2241f51e62b58a0c605ec9a4b29c + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Test <replaceme>test + + + \ No newline at end of file diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index ecd1f07a7d99..870b0fb80800 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,54 @@ public: } }; +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testPlaceholderHTMLPaste) +{ + { + createSwDoc(); + + SwDoc* const pDoc = getSwDoc(); + SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert(u"AAA"_ustr); + pWrtShell->SplitNode(); + pWrtShell->Insert(u"BBB"_ustr); + pWrtShell->SplitNode(); + pWrtShell->Insert(u"CCC"_ustr); + + dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {}); + dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); + } + + createSwDoc("placeholder-bold.fodt"); + + // select placeholder field + SwDoc* const pDoc = getSwDoc(); + SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 5, /*bBasicCall=*/false); + pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, /*bBasicCall=*/false); + + // Paste special as HTML + uno::Sequence aPropertyValues = comphelper::InitPropertySequence( + { { "SelectedFormat", uno::Any(static_cast(SotClipboardFormatId::HTML)) } }); + + dispatchCommand(mxComponent, u".uno:ClipboardFormatItems"_ustr, aPropertyValues); + + CPPUNIT_ASSERT_EQUAL(int(4), getParagraphs()); + + CPPUNIT_ASSERT_EQUAL( + awt::FontWeight::NORMAL, + getProperty(getRun(getParagraph(1), 1, u"Test "_ustr), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL( + awt::FontWeight::BOLD, + getProperty(getRun(getParagraph(1), 2, u"AAA"_ustr), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, + getProperty(getParagraph(2), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, + getProperty(getParagraph(3), u"CharWeight"_ustr)); + CPPUNIT_ASSERT_EQUAL( + awt::FontWeight::NORMAL, + getProperty(getRun(getParagraph(4), 1, u" test"_ustr), u"CharWeight"_ustr)); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf151974) { createSwDoc("tdf151974.odt"); diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 767ce605fbf7..3ce6c858d3ab 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -578,6 +578,13 @@ SvParserState SwHTMLParser::CallParser() aInsertionRangePam.Move( fnMoveBackward ); m_xDoc->getIDocumentRedlineAccess().SplitRedline( aInsertionRangePam ); + if (SwAttrSet const*const pAttrs = pPos->GetNode().GetTextNode()->GetpSwAttrSet()) + { + m_pTargetCharAttrs.reset(new SfxItemSet(*pAttrs->GetPool(), + svl::Items)); + m_pTargetCharAttrs->Put(*pAttrs); + } + m_xDoc->SetTextFormatColl( *m_pPam, m_pCSS1Parser->GetTextCollFromPool( RES_POOLCOLL_STANDARD )); } @@ -4812,6 +4819,13 @@ void SwHTMLParser::SetTextCollAttrs( HTMLAttrContext *pContext ) // set the style m_xDoc->SetTextFormatColl( *m_pPam, pCollToSet ); + if (m_pTargetCharAttrs) + { + std::unique_ptr const pCharSet(new SfxItemSet(*m_pTargetCharAttrs)); + pCharSet->Differentiate(pCollToSet->GetAttrSet()); + m_xDoc->getIDocumentContentOperations().InsertItemSet(*m_pPam, *pCharSet); + } + // if applicable correct the paragraph indent const SvxFirstLineIndentItem & rFirstLine = pCollToSet->GetFirstLineIndent(); const SvxTextLeftMarginItem & rTextLeftMargin = pCollToSet->GetTextLeftMargin(); diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index 33f03ecf3fc3..1f50803633dc 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -500,6 +500,8 @@ class SwHTMLParser : public SfxHTMLParser, public SvtListener /// This is the URL of the outer data if it's not OLE2 or an image. OUString m_aEmbedURL; + std::unique_ptr m_pTargetCharAttrs; + void DeleteFormImpl(); void DocumentDetected();