diff options
Diffstat (limited to 'sw/source/filter/xml/XMLRedlineImportHelper.cxx')
-rw-r--r-- | sw/source/filter/xml/XMLRedlineImportHelper.cxx | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx index 250a31688151..15e6651661b3 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx @@ -31,6 +31,10 @@ #include <IDocumentStylePoolAccess.hxx> #include <tools/datetime.hxx> #include <poolfmt.hxx> +#include <fmtanchr.hxx> +#include <ftnidx.hxx> +#include <txtftn.hxx> +#include <ndtxt.hxx> #include <unoredline.hxx> #include <o3tl/any.hxx> #include <xmloff/xmltoken.hxx> @@ -562,6 +566,73 @@ inline bool XMLRedlineImportHelper::IsReady(RedlineInfo* pRedline) !pRedline->bNeedsAdjustment ); } +/// recursively check if rPos or its anchor (if in fly or footnote) is in redline section +static auto RecursiveContains(SwStartNode const& rRedlineSection, SwNode const& rPos) -> bool +{ + if (rRedlineSection.GetIndex() <= rPos.GetIndex() + && rPos.GetIndex() <= rRedlineSection.EndOfSectionIndex()) + { + return true; + } + // loop to iterate "up" in the node tree and find an anchored XText + for (SwStartNode const* pStartNode = rPos.StartOfSectionNode(); + pStartNode != nullptr && pStartNode->GetIndex() != 0; + pStartNode = pStartNode->StartOfSectionNode()) + { + switch (pStartNode->GetStartNodeType()) + { + case SwNormalStartNode: + case SwTableBoxStartNode: + continue; + break; + case SwFlyStartNode: + { + SwFrameFormat const*const pFormat(pStartNode->GetFlyFormat()); + assert(pFormat); + SwFormatAnchor const& rAnchor(pFormat->GetAnchor()); + if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PAGE) + { + return false; + } + else if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_FLY) + { // anchor is on a start node, avoid skipping it: + pStartNode = rAnchor.GetContentAnchor()->nNode.GetNode().GetStartNode(); + assert(pStartNode); + // pass the next node to recursive call - it will call + // call StartOfSectionNode on it and go back to pStartNode + SwNodeIndex const next(*pStartNode, +1); + return RecursiveContains(rRedlineSection, next.GetNode()); + } + else + { + return RecursiveContains(rRedlineSection, rAnchor.GetContentAnchor()->nNode.GetNode()); + } + } + break; + case SwFootnoteStartNode: + { // sigh ... need to search + for (SwTextFootnote const*const pFootnote : rRedlineSection.GetDoc()->GetFootnoteIdxs()) + { + if (pStartNode == pFootnote->GetStartNode()->GetNode().GetStartNode()) + { + return RecursiveContains(rRedlineSection, pFootnote->GetTextNode()); + } + } + assert(false); + } + break; + case SwHeaderStartNode: + case SwFooterStartNode: + return false; // headers aren't anchored + break; + default: + assert(false); + break; + } + } + return false; +} + void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo) { OSL_ENSURE(nullptr != pRedlineInfo, "need redline info"); @@ -631,6 +702,17 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo) } } } + else if (pRedlineInfo->pContentIndex != nullptr + // should be enough to check 1 position of aPaM bc CheckNodesRange() above + && RecursiveContains(*pRedlineInfo->pContentIndex->GetNode().GetStartNode(), aPaM.GetPoint()->nNode.GetNode())) + { + SAL_WARN("sw.xml", "Recursive change tracking, removing"); + // reuse aPaM to remove it from nodes that will be deleted + *aPaM.GetPoint() = SwPosition(pRedlineInfo->pContentIndex->GetNode()); + aPaM.SetMark(); + *aPaM.GetMark() = SwPosition(*pRedlineInfo->pContentIndex->GetNode().EndOfSectionNode()); + pDoc->getIDocumentContentOperations().DeleteRange(aPaM); + } else { // regular file loading: insert redline |