sw/source/core/doc/DocumentContentOperationsManager.cxx |   26 +++++++++-------
 sw/source/core/doc/doccorr.cxx                          |    2 -
 sw/source/filter/xml/XMLRedlineImportHelper.cxx         |    5 +--
 3 files changed, 19 insertions(+), 14 deletions(-)

New commits:
commit e073e4afe5eb460083944eb22dc8d87ad334877a
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Jan 5 13:17:17 2023 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Jan 6 20:46:03 2023 +0000

    tdf#152710 sw: call and fix DeleteSection() instead
    
    Turns out there's a function to delete a complete nodes array section -
    and it has the same problem?  Why does it move indexes only from
    startnode + 1?  Let's try to fix it to be more consistent.
    
    Change-Id: Iedacc10e29c1646c4ccc85e53a479b0351f5cfcc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145078
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 475e59d29b7a6cc7f058af8ff863b3bb1a2a84a5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145011
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index f50308cd03af..21f67d9a9774 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -2070,6 +2070,18 @@ DocumentContentOperationsManager::CopyRange( SwPaM& 
rPam, SwPosition& rPos,
     return bRet;
 }
 
+static auto GetCorrPosition(SwPaM const& rPam) -> SwPosition
+{
+    // tdf#152710 target position must be on node that survives deletion
+    // so that PaMCorrAbs can invalidate SwUnoCursors properly
+    return rPam.GetPoint()->GetNode().IsContentNode()
+            ? *rPam.GetPoint()
+            : rPam.GetMark()->GetNode().IsContentNode()
+                ? *rPam.GetMark()
+                // this would be the result in SwNodes::RemoveNode()
+                : SwPosition(rPam.End()->GetNode(), SwNodeOffset(+1));
+}
+
 /// Delete a full Section of the NodeArray.
 /// The passed Node is located somewhere in the designated Section.
 void DocumentContentOperationsManager::DeleteSection( SwNode *pNode )
@@ -2087,8 +2099,9 @@ void DocumentContentOperationsManager::DeleteSection( 
SwNode *pNode )
 
     {
         // move all Cursor/StackCursor/UnoCursor out of the to-be-deleted area
-        SwNodeIndex aMvStt( aSttIdx, 1 );
-        SwDoc::CorrAbs( aMvStt, aEndIdx, SwPosition( aSttIdx ), true );
+        SwPaM const range(aSttIdx, aEndIdx);
+        SwPosition const pos(GetCorrPosition(range));
+        ::PaMCorrAbs(range, pos);
     }
 
     m_rDoc.GetNodes().DelNodes( aSttIdx, aEndIdx.GetIndex() - 
aSttIdx.GetIndex() + 1 );
@@ -4243,14 +4256,7 @@ bool 
DocumentContentOperationsManager::DeleteRangeImpl(SwPaM & rPam, SwDeleteFla
     // passed PaM, because it could be a cursor that would be moved!
     SwPaM aDelPam( *rPam.GetMark(), *rPam.GetPoint() );
     {
-        // tdf#152710 target position must be on node that survives deletion
-        // so that PaMCorrAbs can invalidate SwUnoCursors properly
-        SwPosition const pos(aDelPam.GetPoint()->GetNode().IsContentNode()
-                ? *aDelPam.GetPoint()
-                : aDelPam.GetMark()->GetNode().IsContentNode()
-                    ? *aDelPam.GetMark()
-                    // this would be the result in SwNodes::RemoveNode()
-                    : SwPosition(aDelPam.End()->GetNode(), SwNodeOffset(+1)));
+        SwPosition const pos(GetCorrPosition(aDelPam));
         ::PaMCorrAbs(aDelPam, pos);
     }
 
diff --git a/sw/source/core/doc/doccorr.cxx b/sw/source/core/doc/doccorr.cxx
index c26bced7ac00..783e1aa2346f 100644
--- a/sw/source/core/doc/doccorr.cxx
+++ b/sw/source/core/doc/doccorr.cxx
@@ -34,7 +34,7 @@ namespace
     /// returns NULL if no restrictions apply
     const SwStartNode* lcl_FindUnoCursorSection( const SwNode& rNode )
     {
-        const SwStartNode* pStartNode = rNode.StartOfSectionNode();
+        const SwStartNode* pStartNode = rNode.IsStartNode() ? 
rNode.GetStartNode() : rNode.StartOfSectionNode();
         while( ( pStartNode != nullptr ) &&
                ( pStartNode->StartOfSectionNode() != pStartNode ) &&
                // section node is only start node allowing overlapped delete
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx 
b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index 268ddd5cdf25..6d3bb6007ae6 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -718,9 +718,8 @@ void 
XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo)
         SAL_WARN("sw.xml", "Recursive change tracking, removing");
         // reuse aPaM to remove it from nodes that will be deleted
         aPaM.GetPoint()->Assign(pRedlineInfo->pContentIndex->GetNode());
-        aPaM.SetMark();
-        
aPaM.GetMark()->Assign(*pRedlineInfo->pContentIndex->GetNode().EndOfSectionNode());
-        pDoc->getIDocumentContentOperations().DeleteRange(aPaM);
+        aPaM.DeleteMark();
+        
pDoc->getIDocumentContentOperations().DeleteSection(&aPaM.GetPoint()->GetNode());
     }
     else
     {

Reply via email to