sw/qa/extras/unowriter/unowriter.cxx | 3 +++ sw/source/core/unocore/unoobj2.cxx | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-)
New commits: commit ba7a607f79fb0288b9f5a318d84a52936f251b65 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Jul 2 13:16:36 2021 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Jul 2 14:29:17 2021 +0200 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.st...@allotropia.de> 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits