sw/source/core/unocore/unoobj2.cxx | 42 +++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-)
New commits: commit 5f2c15fb652753fddf74c171abdf58295597366d Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Jul 28 17:33:20 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Mon Jul 31 22:14:26 2023 +0200 tdf#149555 sw: convert RANGE_IS_SECTION SwXTextRange if possible The writerfilter import got an exception in SectionPropertyMap::CloseSectionGroup() because XTextRangeToSwPaM() can't handle RANGE_IS_SECTION SwXTextRange. (regression from commit 7ab349296dac79dad3fec09f60348efcbb9ea17e) Change-Id: I38b37fdec64f4699c0fa1a090c72a8676ff386a6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155026 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit 0f39ecfed57f3f32d4f5cadf50b7dd9de77f8d7e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154969 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index f1c5a7e3675a..4eb527c5111e 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1064,20 +1064,40 @@ void SAL_CALL SwXTextRange::setString(const OUString& rString) bool SwXTextRange::GetPositions(SwPaM& rToFill, ::sw::TextRangeMode const eMode) const { - if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition - && eMode == ::sw::TextRangeMode::AllowNonTextNode) + if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition) { if (auto const pSectFormat = static_cast<SwSectionFormat const*>(m_pImpl->m_pTableOrSectionFormat)) { - SwNodeIndex const*const pSectionNode(pSectFormat->GetContent().GetContentIdx()); - assert(pSectionNode); - assert(pSectionNode->GetNodes().IsDocNodes()); - rToFill.GetPoint()->Assign( pSectionNode->GetNode(), SwNodeOffset(1) ); - rToFill.SetMark(); - rToFill.GetMark()->Assign( *pSectionNode->GetNode().EndOfSectionNode(), SwNodeOffset(-1) ); - if (const SwContentNode* pCNd = rToFill.GetMark()->GetContentNode()) - rToFill.GetMark()->AssignEndIndex(*pCNd); - return true; + if (eMode == ::sw::TextRangeMode::AllowNonTextNode) + { + SwNodeIndex const*const pSectionNode(pSectFormat->GetContent().GetContentIdx()); + assert(pSectionNode); + assert(pSectionNode->GetNodes().IsDocNodes()); + rToFill.GetPoint()->Assign( pSectionNode->GetNode(), SwNodeOffset(1) ); + rToFill.SetMark(); + rToFill.GetMark()->Assign( *pSectionNode->GetNode().EndOfSectionNode(), SwNodeOffset(-1) ); + if (const SwContentNode* pCNd = rToFill.GetMark()->GetContentNode()) + rToFill.GetMark()->AssignEndIndex(*pCNd); + return true; + } + else + { + SwPaM aPaM(*pSectFormat->GetContent().GetContentIdx()); + aPaM.Move(fnMoveForward, GoInContent); + assert(aPaM.GetPoint()->GetNode() < *pSectFormat->GetContent().GetContentIdx()->GetNode().EndOfSectionNode()); + aPaM.SetMark(); + *aPaM.GetPoint() = SwPosition(*pSectFormat->GetContent().GetContentIdx()->GetNode().EndOfSectionNode()); + aPaM.Move(fnMoveBackward, GoInContent); + assert(*pSectFormat->GetContent().GetContentIdx() < aPaM.GetPoint()->GetNode()); + // tdf#149555 if there is no table involved, only nested + // sections, then PaM is valid + if (aPaM.GetPoint()->GetNode().FindTableNode() + == aPaM.GetMark()->GetNode().FindTableNode()) + { + rToFill = aPaM; + return true; + } + } } } ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();