summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-07-02 13:16:36 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2021-07-02 14:29:17 +0200
commitba7a607f79fb0288b9f5a318d84a52936f251b65 (patch)
tree5b78ffbba9d98570926925bbf4f839eabe81573a
parentdbdcceb9d77c602ea1161ab0f4e3899071333a92 (diff)
sw: handle RANGE_IS_SECTION in SwXTextRange::getText()
It always returned null. This was missing in 6471d88cb8b61741c51499ac579dd16cb5b67ebf Change-Id: Ibf34c24fdbbbc2f65c6948f58d12f257ccf120ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118286 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx3
-rw-r--r--sw/source/core/unocore/unoobj2.cxx23
2 files changed, 20 insertions, 6 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index dbee7d40a685..e22f71c27ada 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -408,6 +408,7 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSectionAnchorCopyTableAtStart)
xTTS->getTransferableForTextRange(xAnchor));
// check this doesn't throw
+ CPPUNIT_ASSERT(xAnchor->getText().is());
CPPUNIT_ASSERT(xAnchor->getStart().is());
CPPUNIT_ASSERT(xAnchor->getEnd().is());
@@ -467,6 +468,7 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSectionAnchorCopyTableAtEnd)
xTTS->getTransferableForTextRange(xAnchor));
// check this doesn't throw
+ CPPUNIT_ASSERT(xAnchor->getText().is());
CPPUNIT_ASSERT(xAnchor->getStart().is());
CPPUNIT_ASSERT(xAnchor->getEnd().is());
@@ -528,6 +530,7 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testSectionAnchorCopyTable)
xTTS->getTransferableForTextRange(xAnchor));
// check this doesn't throw
+ CPPUNIT_ASSERT(xAnchor->getText().is());
CPPUNIT_ASSERT(xAnchor->getStart().is());
CPPUNIT_ASSERT(xAnchor->getEnd().is());
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index 437bfe8ce6f5..2103220de62b 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -684,8 +684,13 @@ public:
{
if (m_pTableOrSectionFormat)
{
+ assert(m_eRangePosition == RANGE_IS_TABLE || m_eRangePosition == RANGE_IS_SECTION);
StartListening(pTableOrSectionFormat->GetNotifier());
}
+ else
+ {
+ assert(m_eRangePosition != RANGE_IS_TABLE && m_eRangePosition != RANGE_IS_SECTION);
+ }
}
virtual ~Impl() override
@@ -940,17 +945,23 @@ SwXTextRange::getText()
{
SolarMutexGuard aGuard;
- if (!m_pImpl->m_xParentText.is())
+ if (!m_pImpl->m_xParentText.is() && m_pImpl->m_pTableOrSectionFormat)
{
- if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE &&
- m_pImpl->m_pTableOrSectionFormat)
+ std::optional<SwPosition> oPosition;
+ if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE)
{
SwTable const*const pTable = SwTable::FindTable( m_pImpl->m_pTableOrSectionFormat );
SwTableNode const*const pTableNode = pTable->GetTableNode();
- const SwPosition aPosition( *pTableNode );
- m_pImpl->m_xParentText =
- ::sw::CreateParentXText(m_pImpl->m_rDoc, aPosition);
+ oPosition.emplace(*pTableNode);
+ }
+ else
+ {
+ assert(m_pImpl->m_eRangePosition == RANGE_IS_SECTION);
+ auto const pSectFormat(static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat));
+ oPosition.emplace(pSectFormat->GetContent().GetContentIdx()->GetNode());
}
+ m_pImpl->m_xParentText =
+ ::sw::CreateParentXText(m_pImpl->m_rDoc, *oPosition);
}
OSL_ENSURE(m_pImpl->m_xParentText.is(), "SwXTextRange::getText: no text");
return m_pImpl->m_xParentText;