summaryrefslogtreecommitdiff
path: root/sw/source/core/doc
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-08-11 18:39:20 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2016-08-29 13:13:17 +0200
commitd943d4faf92f0b86c25f3cd6fe77ed8a7d4905d1 (patch)
tree620b5623841fe6480e6e4f9e278a59f8d57dbc1d /sw/source/core/doc
parent345b7023b80587e1a022ff7d2ce16e8afb23d9c5 (diff)
Fix SwDoc::AppendDoc for trailing sections
We already treat the StartOfContent node special in the CopyRange function to prevent merging of SwTextNodes. For trailing sections, we have to expand the code to treat EndOfContent special too, because the supplied SwPaM range is handled as [mark, point[, so it previously missed the section end node, which resulted in "unhiding" the last section, if it was the last node in the document. Change-Id: Ie094e2a0182647a49c9ba45d08a7dd2cabe667c6
Diffstat (limited to 'sw/source/core/doc')
-rw-r--r--sw/source/core/doc/docnew.cxx40
1 files changed, 23 insertions, 17 deletions
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 8079e8fb37d2..aeaf70245d41 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -964,20 +964,13 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
SAL_INFO( "sw.pagefrm", "(SwDoc::AppendDoc in " << bDeletePrevious );
// GetEndOfExtras + 1 = StartOfContent == no content node!
- // this ensures, that we have at least two nodes in the SwPaM.
- // @see IDocumentContentOperations::CopyRange
+ // This ensures it won't be merged in the SwTextNode at the position.
SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
- SwNodeIndex aSourceEndIdx( rSource.GetNodes().GetEndOfContent(), -1 );
- SwPaM aCpyPam( aSourceIdx );
-
- if ( aSourceEndIdx.GetNode().IsTextNode() ) {
- aCpyPam.SetMark();
- // moves to the last content node before EOC; for single paragraph
- // documents this would result in [n, n], which is considered empty
- aCpyPam.Move( fnMoveForward, fnGoDoc );
- }
- else
- aCpyPam = SwPaM( aSourceIdx, aSourceEndIdx );
+ // CopyRange works on the range a [mark, point[ and considers an
+ // index < point outside the selection.
+ // @see IDocumentContentOperations::CopyRange
+ SwNodeIndex aSourceEndIdx( rSource.GetNodes().GetEndOfContent(), 0 );
+ SwPaM aCpyPam( aSourceIdx, aSourceEndIdx );
#ifdef DBG_UTIL
SAL_INFO( "sw.docappend", "NodeType 0x" << std::hex << (int) aSourceIdx.GetNode().GetNodeType()
@@ -994,10 +987,8 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
SAL_INFO( "sw.docappend", ".." );
SAL_INFO( "sw.docappend", "NodeType 0x" << std::hex << (int) aSourceEndIdx.GetNode().GetNodeType()
<< std::dec << " " << aSourceEndIdx.GetNode().GetIndex() );
- aSourceEndIdx++;
SAL_INFO( "sw.docappend", "NodeType 0x" << std::hex << (int) aSourceEndIdx.GetNode().GetNodeType()
<< std::dec << " " << aSourceEndIdx.GetNode().GetIndex() );
- aSourceEndIdx--;
SAL_INFO( "sw.docappend", "Src-Nd: " << CNTNT_DOC( &rSource ) );
SAL_INFO( "sw.docappend", "Nd: " << CNTNT_DOC( this ) );
#endif
@@ -1041,9 +1032,23 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
}
// Otherwise we have to handle SwPlaceholderNodes as first node
- if ( pTargetPageDesc ) {
+ if ( pTargetPageDesc )
+ {
+ 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 );
OUString name = pTargetPageDesc->GetName();
pTargetShell->InsertPageBreak( &name, nStartPageNumber );
+ if ( !bIsTextNode )
+ {
+ pTargetShell->SttEndDoc( false );
+ --aBreakIdx;
+ GetNodes().Delete( aBreakIdx, 1 );
+ }
// 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
@@ -1103,7 +1108,8 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
this->GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, nullptr );
this->getIDocumentFieldsAccess().LockExpFields();
- // Position where the appended doc starts. Will be filled in later (uses GetEndOfContent() because SwNodeIndex has no default ctor).
+ // Position where the appended doc starts. Will be filled in later.
+ // Initially uses GetEndOfContent() because SwNodeIndex has no default ctor.
SwNodeIndex aStartAppendIndex( GetNodes().GetEndOfContent() );
{