diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-12-16 13:36:46 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-12-24 10:36:24 +0100 |
commit | 6df93ba3fd93110b5d5678446d9a97b034edfc28 (patch) | |
tree | 79ac1bd76be5a90d8d5a76fdb65aab000243aae7 | |
parent | 7c6cee66e9db951f64b07cc2d462e09156e090af (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>
(cherry picked from commit 42448f48bb48a13d6618a181b12840db6d85c574)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126945
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit eb4ab0c70c549cabf5625a824eee950f82fbf622)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127064
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index ae2f24a92a8a..d3ff264f2a3a 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -1082,19 +1082,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 |