sw/source/core/unocore/unoobj2.cxx |   42 +++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 11 deletions(-)

New commits:
commit 0f39ecfed57f3f32d4f5cadf50b7dd9de77f8d7e
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Jul 28 17:33:20 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Jul 28 19:36:20 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>

diff --git a/sw/source/core/unocore/unoobj2.cxx 
b/sw/source/core/unocore/unoobj2.cxx
index 1b02cb5a0b27..01682ef48587 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -1049,20 +1049,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();

Reply via email to