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:13:48 +0200
commit70d624adfc9744373aaa5da47dd7d3bb8ff8c85f (patch)
tree5f1c4a4007d537d187060d1b9b275cceddc1d39e
parent3443ccada744dc6b5f9282df7f0b3016d2e92079 (diff)
sw: handle RANGE_IS_SECTION in SwXTextRange::getText()
It always returned null. This was missing in 6471d88cb8b61741c51499ac579dd16cb5b67ebf Change-Id: Ibf34c24fdbbbc2f65c6948f58d12f257ccf120ae
-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 48c3ed7ba90d..b82001b07a84 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -392,6 +392,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());
@@ -451,6 +452,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());
@@ -512,6 +514,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 e7673186713c..05b0b7e4fc50 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -722,8 +722,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
@@ -983,17 +988,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;