sw/inc/node.hxx                  |    3 ++-
 sw/source/core/docnode/node.cxx  |   24 ++++++++++++++++++++++++
 sw/source/filter/html/swhtml.cxx |    7 +++----
 sw/source/filter/xml/xmlimp.cxx  |    3 +--
 4 files changed, 30 insertions(+), 7 deletions(-)

New commits:
commit 5b98500614f179b8c725a8476d72ff84327c3716
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Sep 20 16:38:40 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Sep 20 21:23:59 2022 +0200

    add CanJoinNext method that takes a SwPosition*
    
    part of the process of hiding the internals of SwPosition
    
    Change-Id: I401fa4d98a2e53a082bfb39f3d13315261a0a2ef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140246
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index 0d749899b078..68a33263124f 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -407,7 +407,8 @@ public:
     virtual SwContentNode *JoinNext();
     /** Is it possible to join two nodes?
        In pIdx the second position can be returned. */
-    bool CanJoinNext( SwNodeIndex* pIdx =nullptr ) const;
+    bool CanJoinNext( SwNodeIndex* pIdx = nullptr ) const;
+    bool CanJoinNext( SwPosition* pIdx ) const;
     bool CanJoinPrev( SwNodeIndex* pIdx =nullptr ) const;
 
     void MakeStartIndex( SwContentIndex * pIdx )   { pIdx->Assign( this, 0 ); }
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index e8d415d9d1c2..04d9e3f354bd 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -1863,6 +1863,30 @@ bool SwContentNode::CanJoinNext( SwNodeIndex* pIdx ) 
const
     return true;
 }
 
+/// Can we join two Nodes?
+/// We can return the 2nd position in pIdx.
+bool SwContentNode::CanJoinNext( SwPosition* pIdx ) const
+{
+    const SwNodes& rNds = GetNodes();
+    SwNodeIndex aIdx( *this, 1 );
+
+    const SwNode* pNd = this;
+    while( aIdx < rNds.Count()-1 &&
+        (( pNd = &aIdx.GetNode())->IsSectionNode() ||
+            ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsSectionNode() 
)))
+        ++aIdx;
+
+    if (rNds.Count()-1 == aIdx.GetIndex())
+        return false;
+    if (!lcl_CheckMaxLength(*this, *pNd))
+    {
+        return false;
+    }
+    if( pIdx )
+        pIdx->Assign(aIdx);
+    return true;
+}
+
 /// Can we join two Nodes?
 /// We can return the 2nd position in pIdx.
 bool SwContentNode::CanJoinPrev( SwNodeIndex* pIdx ) const
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index fa45f91406e3..8a31aa197ec9 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -768,13 +768,13 @@ void SwHTMLParser::Continue( HtmlTokenId nToken )
                 if( m_pSttNdIdx->GetIndex()+1 == 
m_pPam->GetBound().GetNodeIndex() )
                 {
                     const sal_Int32 nCntPos = 
m_pPam->GetBound().GetContentIndex();
-                    m_pPam->GetBound().nContent.Assign( pTextNode,
+                    m_pPam->GetBound().SetContent(
                                     pTextNode->GetText().getLength() + nCntPos 
);
                 }
                 if( m_pSttNdIdx->GetIndex()+1 == m_pPam->GetBound( false 
).GetNodeIndex() )
                 {
                     const sal_Int32 nCntPos = m_pPam->GetBound( false 
).GetContentIndex();
-                    m_pPam->GetBound( false ).nContent.Assign( pTextNode,
+                    m_pPam->GetBound( false ).SetContent(
                                     pTextNode->GetText().getLength() + nCntPos 
);
                 }
 #endif
@@ -834,10 +834,9 @@ void SwHTMLParser::Continue( HtmlTokenId nToken )
             }
             else if( nullptr != ( pCurrentNd = m_xDoc->GetNodes()[ nNodeIdx 
]->GetTextNode()) && !bHasFlysOrMarks )
             {
-                if( pCurrentNd->CanJoinNext( &pPos->nNode ))
+                if( pCurrentNd->CanJoinNext( pPos ))
                 {
                     SwTextNode* pNextNd = pPos->GetNode().GetTextNode();
-                    pPos->nContent.Assign( pNextNd, 0 );
                     m_pPam->SetMark(); m_pPam->DeleteMark();
                     pNextNd->JoinPrev();
                 }
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 352d658a24d8..565d3f201e1d 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -741,7 +741,7 @@ void SwXMLImport::endDocument()
             {
                 // Id we're in insert mode, the empty node is joined with
                 // the next and the previous one.
-                if( pCurrNd->CanJoinNext( &pPos->nNode ))
+                if( pCurrNd->CanJoinNext( pPos ))
                 {
                     SwTextNode* pNextNd = pPos->GetNode().GetTextNode();
                     bool endNodeFound = 
pDoc->GetNodes()[nNodeIdx-1]->IsEndNode();
@@ -754,7 +754,6 @@ void SwXMLImport::endDocument()
                         
pNextNd->ChgFormatColl(pLastPar->GetTextNode()->GetTextColl());
                     }
 
-                    pPos->nContent.Assign( pNextNd, 0 );
                     pPaM->SetMark(); pPaM->DeleteMark();
                     pNextNd->JoinPrev();
 

Reply via email to