diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2022-02-07 17:26:32 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-02-09 10:58:41 +0100 |
commit | 9d30e168112bc5c3c7f2dfc029f293c540ebb280 (patch) | |
tree | e8dcd2afa593b6d08acc013331c7ce4fe281d411 /sw | |
parent | 0bc1f4aba10194547a8169eb568cc62e84ec89db (diff) |
tdf#147206 writerfilter: fix end position of hyperlink in ToX
(regression from commit 58a86af36295b4fc1e07c0bd38f74530a2ce0f08)
Change-Id: Ied4c26255b60f4320f38432ef5e2e27882b7a135
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129681
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter3.cxx | 65 |
1 files changed, 65 insertions, 0 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"); |