diff options
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter3.cxx | 65 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 9 |
2 files changed, 73 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index a647db3f1f2b..a0a2d5c67467 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -37,6 +37,7 @@ #include <svx/svdpage.hxx> #include <ndtxt.hxx> #include <txtfld.hxx> +#include <toxmgr.hxx> #include <IDocumentFieldsAccess.hxx> #include <IDocumentLinksAdministration.hxx> #include <IDocumentRedlineAccess.hxx> @@ -635,6 +636,70 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf139737) Scheduler::ProcessEventsToIdle(); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf147206) +{ + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // insert empty paragraph and heading text + pWrtShell->SplitNode(); + pWrtShell->Insert("abc"); + pWrtShell->SplitNode(); + + // set one to heading so there will be an entry in the tox + pWrtShell->Up(false, 1); + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence({ + { "Style", uno::makeAny(OUString("Heading 1")) }, + { "FamilyName", uno::makeAny(OUString("ParagraphStyles")) }, + }); + dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues); + + pWrtShell->EndOfSection(false); + + // insert table of contents + SwTOXMgr mgr(pWrtShell); + SwTOXDescription desc{ TOX_CONTENT }; + mgr.UpdateOrInsertTOX(desc, nullptr, nullptr); + + // get url of heading cross reference mark + IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess()); + auto const headingMark + = std::find_if(rIDMA.getAllMarksBegin(), rIDMA.getAllMarksEnd(), [](auto const* const it) { + return it->GetName().startsWith( + IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix()); + }); + CPPUNIT_ASSERT(headingMark != rIDMA.getAllMarksEnd()); + OUString const headingLink("#" + (*headingMark)->GetName()); + + // select tox entry + pWrtShell->SttEndDoc(false); + pWrtShell->Up(false, 1); + pWrtShell->EndPara(true); + + rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell); + xTransfer->Copy(); + + pWrtShell->SttEndDoc(true); + + // Paste special as RTF + TransferableDataHelper helper(xTransfer); + SwTransferable::PasteFormat(*pWrtShell, helper, SotClipboardFormatId::RTF); + Scheduler::ProcessEventsToIdle(); + + // check hyperlinkering + CPPUNIT_ASSERT_EQUAL( + headingLink, getProperty<OUString>(getRun(getParagraph(1), 1, "abc\t1"), "HyperLinkURL")); + CPPUNIT_ASSERT_EQUAL( + OUString(), getProperty<OUString>(getRun(getParagraph(2), 1, OUString()), "HyperLinkURL")); + CPPUNIT_ASSERT_EQUAL( + OUString(), + getProperty<OUString>(getRun(getParagraph(3), 1, "Table of Contents"), "HyperLinkURL")); + CPPUNIT_ASSERT_EQUAL( + headingLink, getProperty<OUString>(getRun(getParagraph(4), 1, "abc\t1"), "HyperLinkURL")); + CPPUNIT_ASSERT_EQUAL( + OUString(), getProperty<OUString>(getRun(getParagraph(5), 1, OUString()), "HyperLinkURL")); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf144840) { SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf144840.odt"); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index a6694da7f3fa..e9f53d461deb 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -7101,7 +7101,14 @@ void DomainMapper_Impl::PopFieldContext() } else if (!pContext->GetHyperlinkURL().isEmpty() && xCrsr.is()) { - xCrsr->gotoEnd( true ); + if (m_aTextAppendStack.top().xInsertPosition.is()) + { + xCrsr->gotoRange(m_aTextAppendStack.top().xInsertPosition, true); + } + else + { + xCrsr->gotoEnd(true); + } // Draw components (like comments) need hyperlinks set differently SvxUnoTextRangeBase* pDrawText = dynamic_cast<SvxUnoTextRangeBase*>(xCrsr.get()); |