diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-08-11 18:39:20 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-08-29 13:13:17 +0200 |
commit | d943d4faf92f0b86c25f3cd6fe77ed8a7d4905d1 (patch) | |
tree | 620b5623841fe6480e6e4f9e278a59f8d57dbc1d /sw/source/core/docnode | |
parent | 345b7023b80587e1a022ff7d2ce16e8afb23d9c5 (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/docnode')
-rw-r--r-- | sw/source/core/docnode/nodes.cxx | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx index 7927af3502a8..4b04d07f5469 100644 --- a/sw/source/core/docnode/nodes.cxx +++ b/sw/source/core/docnode/nodes.cxx @@ -1695,24 +1695,30 @@ void SwNodes::CopyNodes( const SwNodeRange& rRange, !pAktNode->m_pStartOfSection->IsSectionNode() ) ) ++aRg.aStart; - // if aEnd-1 points to no ContentNode, search previous one - --aRg.aEnd; - // #i107142#: if aEnd is start node of a special section, do nothing. - // Otherwise this could lead to crash: going through all previous - // special section nodes and then one before the first. - if (aRg.aEnd.GetNode().StartOfSectionIndex() != 0) + const SwNode *aEndNode = &aRg.aEnd.GetNode(); + int nIsEndOfContent = (aEndNode == &aEndNode->GetNodes().GetEndOfContent()) ? 1 : 0; + + if (0 == nIsEndOfContent) { - while( ((pAktNode = & aRg.aEnd.GetNode())->GetStartNode() && - !pAktNode->IsSectionNode() ) || - ( pAktNode->IsEndNode() && - ND_STARTNODE == pAktNode->m_pStartOfSection->GetNodeType()) ) + // if aEnd-1 points to no ContentNode, search previous one + --aRg.aEnd; + // #i107142#: if aEnd is start node of a special section, do nothing. + // Otherwise this could lead to crash: going through all previous + // special section nodes and then one before the first. + if (aRg.aEnd.GetNode().StartOfSectionIndex() != 0) { - --aRg.aEnd; + while( ((pAktNode = & aRg.aEnd.GetNode())->GetStartNode() && + !pAktNode->IsSectionNode() ) || + ( pAktNode->IsEndNode() && + ND_STARTNODE == pAktNode->m_pStartOfSection->GetNodeType()) ) + { + --aRg.aEnd; + } } + ++aRg.aEnd; } - ++aRg.aEnd; - // if in same array, check insertion position + // is there anything left to copy? if( aRg.aStart >= aRg.aEnd ) return; @@ -1787,7 +1793,7 @@ void SwNodes::CopyNodes( const SwNodeRange& rRange, if (nDistance < nNodeCnt) nNodeCnt -= nDistance; else - nNodeCnt = 1; + nNodeCnt = 1 - nIsEndOfContent; aRg.aStart = pAktNode->EndOfSectionIndex(); @@ -1815,7 +1821,7 @@ void SwNodes::CopyNodes( const SwNodeRange& rRange, if (nDistance < nNodeCnt) nNodeCnt -= nDistance; else - nNodeCnt = 1; + nNodeCnt = 1 - nIsEndOfContent; aRg.aStart = pAktNode->EndOfSectionIndex(); if( bNewFrames && pSectNd && @@ -1840,6 +1846,9 @@ void SwNodes::CopyNodes( const SwNodeRange& rRange, --nLevel; ++aInsPos; // EndNode already exists } + else if( 1 == nNodeCnt && 1 == nIsEndOfContent ) + // we have reached the EndOfContent node - nothing to do! + continue; else if( !pAktNode->m_pStartOfSection->IsSectionNode() ) { // create a section at the original InsertPosition |