summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-12-16 13:36:46 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2021-12-16 18:17:46 +0100
commit42448f48bb48a13d6618a181b12840db6d85c574 (patch)
tree873fc184c8b64e58b706aa8978343a8e273ebfb2 /sw
parentb8f68233b8dc5a009396141fba6e47867e70f342 (diff)
tdf#144565 sw_redlinehide: fix mailmerge when flys anchored at last node
The InsertPageBreak() calls SplitNode() which is not ideal as the flys anchored at the last node of the document may end up anchored to the newly inserted node and this one will be removed again a bit further on: GetNodes().Delete( aDelIdx, iDelNodes ); ... which is what crashes, when the SwNodeIndex of the anchor is moved hard to a different node, which causes inconsistencies such as: sw/source/core/text/txtfrm.cxx:1263: TextFrameIndex SwTextFrame::MapModelToView(const SwTextNode*, sal_Int32) const: Assertion `static_cast<SwTextNode*>(const_cast<sw::BroadcastingModify*>(SwFrame::GetDep())) == pNode' failed. Instead, always use AppendTextNode() and then set the break item directly, which even simplifies the code. (reportedly a regression from 166b5010b402a41b192b1659093a25acf9065fd9 although i wasn't able to find an earlier version that didn't crash in some way) Change-Id: I4cac74fc86fc505f62b14cf0d7a7f9689c7402ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126921 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/doc/docnew.cxx21
1 files changed, 8 insertions, 13 deletions
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index a59e1687ad67..667cb4283207 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -1085,19 +1085,14 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
{
SwNodeIndex aBreakIdx( GetNodes().GetEndOfContent(), -1 );
SwPosition aBreakPos( aBreakIdx );
- // InsertPageBreak just works on SwTextNode nodes, so make
- // sure the last node is one!
- bool bIsTextNode = aBreakIdx.GetNode().IsTextNode();
- if ( !bIsTextNode )
- getIDocumentContentOperations().AppendTextNode( aBreakPos );
- const OUString name = pTargetPageDesc->GetName();
- pTargetShell->InsertPageBreak( &name, nStartPageNumber );
- if ( !bIsTextNode )
- {
- pTargetShell->SttEndDoc( false );
- --aBreakIdx;
- GetNodes().Delete( aBreakIdx );
- }
+ // insert new node - will be removed at the end...
+ // (don't SplitNode() as it may move flys to the wrong node)
+ getIDocumentContentOperations().AppendTextNode(aBreakPos);
+ SwFormatPageDesc pageDesc(pTargetPageDesc);
+ pageDesc.SetNumOffset(nStartPageNumber);
+ // set break on the last paragraph
+ getIDocumentContentOperations().InsertPoolItem(SwPaM(aBreakPos),
+ pageDesc, SetAttrMode::DEFAULT, pTargetShell->GetLayout());
// 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