diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2023-01-05 13:17:17 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2023-01-05 18:26:02 +0000 |
commit | 475e59d29b7a6cc7f058af8ff863b3bb1a2a84a5 (patch) | |
tree | 8965c897d901bdbb6e97a04df22a5fcdb477966a | |
parent | 8e05bdd26f21fc304978ff3b454cf355841ec75f (diff) |
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.stahl@allotropia.de>
-rw-r--r-- | sw/source/core/doc/DocumentContentOperationsManager.cxx | 26 | ||||
-rw-r--r-- | sw/source/core/doc/doccorr.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/xml/XMLRedlineImportHelper.cxx | 5 |
3 files changed, 19 insertions, 14 deletions
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 8f2318a0b1c4..4376278d7dc1 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 ); @@ -4229,14 +4242,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 { |