summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-02-07 17:26:32 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-02-10 13:18:47 +0100
commit5c0497337cb2cc34091d1ae58dab288a8a9a5454 (patch)
tree1fe44a3436eaae55986349ae40e795ccd1a37bf8
parentb87597babf1b628aa9a80042956d05f44f542fae (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> (cherry picked from commit 9d30e168112bc5c3c7f2dfc029f293c540ebb280) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129618 Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter3.cxx65
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx9
2 files changed, 73 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index faad2989afec..cf8c4e07e9b6 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -44,6 +44,7 @@
#include <svx/svdpage.hxx>
#include <ndtxt.hxx>
#include <txtfld.hxx>
+#include <toxmgr.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <IDocumentLinksAdministration.hxx>
#include <IDocumentRedlineAccess.hxx>
@@ -535,6 +536,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 6080f2a70ae1..4b0f3f6c4e75 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -7042,7 +7042,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());