diff options
-rw-r--r-- | sw/qa/extras/mailmerge/data/empty.odt | bin | 0 -> 7241 bytes | |||
-rw-r--r-- | sw/qa/extras/mailmerge/mailmerge.cxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 26 |
3 files changed, 31 insertions, 0 deletions
diff --git a/sw/qa/extras/mailmerge/data/empty.odt b/sw/qa/extras/mailmerge/data/empty.odt Binary files differnew file mode 100644 index 000000000000..311cb06e575e --- /dev/null +++ b/sw/qa/extras/mailmerge/data/empty.odt diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx index 3ac972406c40..37bbed4a2df0 100644 --- a/sw/qa/extras/mailmerge/mailmerge.cxx +++ b/sw/qa/extras/mailmerge/mailmerge.cxx @@ -346,6 +346,11 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf89214, "tdf89214.odt", "10-testing-addresses CPPUNIT_ASSERT(!getProperty<OUString>(xParagraph, "ListId").isEmpty()); } +DECLARE_SHELL_MAILMERGE_TEST(testTdf90230, "empty.odt", "10-testing-addresses.ods", "testing-addresses") +{ + // MM of an empty document caused an assertion in the SwIndexReg dtor. + executeMailMerge(); +} #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index c6d353bd3b10..95a3ded11f8d 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -985,6 +985,32 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu if ( pTargetPageDesc ) { OUString 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 |