summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-04-10 11:54:03 +0200
committerJan Holesovsky <kendy@collabora.com>2015-04-10 14:11:34 +0200
commita9d3de2994438bc1891d733cb7f88f3cefe3db43 (patch)
tree98e5563f4c4e9703937270a3df067f34b45d79f9
parenttdf#89214 SwDoc::GetUniqueNumRuleName: always return pChkStr if it's unused (diff)
downloadcore-private/kendy/mailmerge-05.tar.gz
core-private/kendy/mailmerge-05.zip
tdf#90230 SwDoc::AppendDoc: take care of marks when inserting page break private/kendy/mailmerge-05
SwDoc::AppendDoc() inserts nodes from an other document, and before doing that, it inserts a page break at the end of the document. In case there are marks at the end of the last paragraph, the insertion of the page break moves them to the next page. This is a rare situation, but happens e.g. when the source document is an empty one: then MM puts a mark at the first paragraph of each inserted MM part, and then the first paragraph == the last paragraph, so the mark of the only paragraph in the document gets moved to the next page. This is a problem on its own, but is detected by the SwIndexReg dtor when that empty paragraph gets deleted later in SwNodes::Delete() called by SwDoc::AppendDoc(), resulting in an assertion failure. Triggered by commit a305a2c91420652db450b7f8edd140e1d69f42cf (use bookmarks to mark mailmerge parts in a mailmerge document (fdo#80823), 2014-10-20), these not adjusted bookmarks were not detected before. Unit test not included, as the entire mailmerge unit test framework is missing in 4.1. Conflicts: sw/qa/extras/mailmerge/mailmerge.cxx Change-Id: I89775b477a2fd3182b2bc87144aed2bfe7912aff
-rw-r--r--sw/source/core/doc/docnew.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index a25ee2b76d21..c481c0d388b6 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -1211,6 +1211,32 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
if ( pTargetPageDesc ) {
String name = pTargetPageDesc->GetName();
pTargetShell->InsertPageBreak( &name, nStartPageNumber );
+
+ // There is now a new empty text node on the new page. If it has
+ // any marks, those are from the previous page: move them back
+ // there, otherwise later we can't delete that empty text node.
+ SwNodeIndex aNodeIndex(GetNodes().GetEndOfContent(), -1);
+ if (SwTxtNode* pTxtNode = aNodeIndex.GetNode().GetTxtNode())
+ {
+ // Position of the last paragraph on the previous page.
+ --aNodeIndex;
+ SwPaM aPaM(aNodeIndex);
+ // Collect the marks starting or ending at this text node.
+ std::set<sw::mark::IMark*> aSeenMarks;
+ IDocumentMarkAccess* pMarkAccess = getIDocumentMarkAccess();
+ for (const SwIndex* pIndex = pTxtNode->GetFirstIndex(); pIndex; pIndex = pIndex->GetNext())
+ {
+ sw::mark::IMark* pMark = const_cast<sw::mark::IMark*>(pIndex->GetMark());
+ if (!pMark)
+ continue;
+ if (aSeenMarks.find(pMark) != aSeenMarks.end())
+ continue;
+ aSeenMarks.insert(pMark);
+ }
+ // And move them back.
+ for (sw::mark::IMark* pMark : aSeenMarks)
+ pMarkAccess->repositionMark(pMark, aPaM);
+ }
}
}
#ifdef DBG_UTIL