Kaydet (Commit) 9099e21b authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Björn Michaelsen

Fix single node CopyRange

Previously there was a restriction for the range to contain at
least two nodes.

Change-Id: Iadf21d3928303c2ab8df0d93dabd969ed1ff7e09
Reviewed-on: https://gerrit.libreoffice.org/10972Reviewed-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@canonical.com>
Tested-by: 's avatarBjörn Michaelsen <bjoern.michaelsen@canonical.com>
üst 65981011
...@@ -70,9 +70,6 @@ public: ...@@ -70,9 +70,6 @@ public:
The position can be in the same or in an another document. It can also The position can be in the same or in an another document. It can also
be within the range! be within the range!
\warning The range has to include at least two nodes or has to be a
SwDoc::IsColumnSelection!
Normally this function should work only with content nodes. But there Normally this function should work only with content nodes. But there
is a special case used by SwDoc::Paste, which starts the SwPaM at the is a special case used by SwDoc::Paste, which starts the SwPaM at the
content start node. This position doesn't contain any content: content start node. This position doesn't contain any content:
......
...@@ -1586,7 +1586,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons ...@@ -1586,7 +1586,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons
bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection(); bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();
// Catch if there's no copy to do // Catch if there's no copy to do
if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) ) if( !rPam.HasMark() || ( *pStt > *pEnd && !bColumnSel ) )
return false; return false;
// Prevent copying in Flys that are anchored in the area // Prevent copying in Flys that are anchored in the area
...@@ -3111,7 +3111,8 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( ...@@ -3111,7 +3111,8 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
const SwPaM* pCopiedPaM, const SwPaM* pCopiedPaM,
const bool bMakeNewFrms, const bool bMakeNewFrms,
const bool bDelRedlines, const bool bDelRedlines,
const bool bCopyFlyAtFly ) const const bool bCopyFlyAtFly,
const bool bMergedFirstNode ) const
{ {
SwDoc* pDest = rInsPos.GetNode().GetDoc(); SwDoc* pDest = rInsPos.GetNode().GetDoc();
...@@ -3119,13 +3120,17 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( ...@@ -3119,13 +3120,17 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
SwNodeIndex aSavePos( rInsPos, -1 ); SwNodeIndex aSavePos( rInsPos, -1 );
bool bEndIsEqualEndPos = rInsPos == rRg.aEnd; bool bEndIsEqualEndPos = rInsPos == rRg.aEnd;
m_rSwdoc.GetNodes()._CopyNodes( rRg, rInsPos, bMakeNewFrms, true ); SwNodeRange aRg( rRg );
++aSavePos; if ( bMergedFirstNode )
if( bEndIsEqualEndPos ) aRg.aStart++;
if ( aRg.aStart <= aRg.aEnd )
m_rSwdoc.GetNodes()._CopyNodes( aRg, rInsPos, bMakeNewFrms, true );
if ( !bMergedFirstNode )
++aSavePos;
if ( bEndIsEqualEndPos )
((SwNodeIndex&)rRg.aEnd) = aSavePos; ((SwNodeIndex&)rRg.aEnd) = aSavePos;
aRedlRest.Restore(); aRedlRest.Restore();
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
{ {
//JP 17.06.99: Bug 66973 - check count only if the selection is in //JP 17.06.99: Bug 66973 - check count only if the selection is in
...@@ -3139,9 +3144,9 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( ...@@ -3139,9 +3144,9 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
!aTmpI.GetNode().IsEndNode() ) !aTmpI.GetNode().IsEndNode() )
{ {
// If the range starts with a SwStartNode, it isn't copied // If the range starts with a SwStartNode, it isn't copied
sal_uInt16 offset = (rRg.aStart.GetNode().GetNodeType() != ND_STARTNODE) ? 1 : 0; sal_uInt16 offset = (aRg.aStart.GetNode().GetNodeType() != ND_STARTNODE) ? 1 : 0;
OSL_ENSURE( rInsPos.GetIndex() - aSavePos.GetIndex() == OSL_ENSURE( rInsPos.GetIndex() - aSavePos.GetIndex() ==
rRg.aEnd.GetIndex() - rRg.aStart.GetIndex() - 1 + offset, aRg.aEnd.GetIndex() - aRg.aStart.GetIndex() - 1 + offset,
"An insufficient number of nodes were copied!" ); "An insufficient number of nodes were copied!" );
} }
} }
...@@ -3149,7 +3154,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( ...@@ -3149,7 +3154,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
{ {
::sw::UndoGuard const undoGuard(pDest->GetIDocumentUndoRedo()); ::sw::UndoGuard const undoGuard(pDest->GetIDocumentUndoRedo());
CopyFlyInFlyImpl( rRg, nEndContentIndex, aSavePos, bCopyFlyAtFly ); CopyFlyInFlyImpl( rRg, nEndContentIndex, aSavePos, bCopyFlyAtFly, bMergedFirstNode );
} }
SwNodeRange aCpyRange( aSavePos, rInsPos ); SwNodeRange aCpyRange( aSavePos, rInsPos );
...@@ -3175,7 +3180,8 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl( ...@@ -3175,7 +3180,8 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
const SwNodeRange& rRg, const SwNodeRange& rRg,
const sal_Int32 nEndContentIndex, const sal_Int32 nEndContentIndex,
const SwNodeIndex& rStartIdx, const SwNodeIndex& rStartIdx,
const bool bCopyFlyAtFly ) const const bool bCopyFlyAtFly,
const bool bMergedFirstNode ) const
{ {
// First collect all Flys, sort them according to their ordering number, // First collect all Flys, sort them according to their ordering number,
// and then only copy them. This maintains the ordering numbers (which are only // and then only copy them. This maintains the ordering numbers (which are only
...@@ -3295,6 +3301,9 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl( ...@@ -3295,6 +3301,9 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
++aIdx; ++aIdx;
} }
if ( bMergedFirstNode )
nAnchorTxtNdNumInRange--;
if ( !bAnchorTxtNdFound ) if ( !bAnchorTxtNdFound )
{ {
// This case can *not* happen, but to be robust take the first // This case can *not* happen, but to be robust take the first
...@@ -4063,7 +4072,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4063,7 +4072,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
SwPosition* pEnd = rPam.End(); SwPosition* pEnd = rPam.End();
// Catch when there's no copy to do. // Catch when there's no copy to do.
if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) || if( !rPam.HasMark() || ( *pStt > *pEnd && !bColumnSel ) ||
//JP 29.6.2001: 88963 - dont copy if inspos is in region of start to end //JP 29.6.2001: 88963 - dont copy if inspos is in region of start to end
//JP 15.11.2001: don't test inclusive the end, ever exclusive //JP 15.11.2001: don't test inclusive the end, ever exclusive
( pDoc == &m_rSwdoc && *pStt <= rPos && rPos < *pEnd )) ( pDoc == &m_rSwdoc && *pStt <= rPos && rPos < *pEnd ))
...@@ -4151,6 +4160,8 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4151,6 +4160,8 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
pNumRuleToPropagate = 0; pNumRuleToPropagate = 0;
} }
bool bHandledStartNode = false;
// This do/while block is only there so that we can break out of it! // This do/while block is only there so that we can break out of it!
do { do {
if( pSttTxtNd ) if( pSttTxtNd )
...@@ -4158,6 +4169,8 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4158,6 +4169,8 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
// Don't copy the beginning completely? // Don't copy the beginning completely?
if( !bCopyCollFmt || bColumnSel || pStt->nContent.GetIndex() ) if( !bCopyCollFmt || bColumnSel || pStt->nContent.GetIndex() )
{ {
bHandledStartNode = true;
SwIndex aDestIdx( rPos.nContent ); SwIndex aDestIdx( rPos.nContent );
bool bCopyOk = false; bool bCopyOk = false;
if( !pDestTxtNd ) if( !pDestTxtNd )
...@@ -4233,18 +4246,11 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4233,18 +4246,11 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
pEnd->nContent -= nCpyLen; pEnd->nContent -= nCpyLen;
} }
if( bOneNode ) if( bCopyCollFmt && bOneNode )
{ {
if( bCopyCollFmt ) pSttTxtNd->CopyCollFmt( *pDestTxtNd );
{ POP_NUMRULE_STATE
pSttTxtNd->CopyCollFmt( *pDestTxtNd );
POP_NUMRULE_STATE
}
break;
} }
aRg.aStart++;
} }
} }
else if( pDestTxtNd ) else if( pDestTxtNd )
...@@ -4301,7 +4307,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4301,7 +4307,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
} }
pDestTxtNd = aInsPos.GetNode().GetTxtNode(); pDestTxtNd = aInsPos.GetNode().GetTxtNode();
if( pEndTxtNd ) if( pEndTxtNd && (!bOneNode || !bHandledStartNode) )
{ {
SwIndex aDestIdx( rPos.nContent ); SwIndex aDestIdx( rPos.nContent );
if( !pDestTxtNd ) if( !pDestTxtNd )
...@@ -4345,7 +4351,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4345,7 +4351,7 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
if( bCopyAll || aRg.aStart != aRg.aEnd ) if( bCopyAll || aRg.aStart != aRg.aEnd )
{ {
SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange ); SfxItemSet aBrkSet( pDoc->GetAttrPool(), aBreakSetRange );
if( pSttTxtNd && bCopyCollFmt && pDestTxtNd->HasSwAttrSet() ) if( !bOneNode && pSttTxtNd && bCopyCollFmt && pDestTxtNd->HasSwAttrSet() )
{ {
aBrkSet.Put( *pDestTxtNd->GetpSwAttrSet() ); aBrkSet.Put( *pDestTxtNd->GetpSwAttrSet() );
if( SFX_ITEM_SET == aBrkSet.GetItemState( RES_BREAK, false ) ) if( SFX_ITEM_SET == aBrkSet.GetItemState( RES_BREAK, false ) )
...@@ -4357,13 +4363,15 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos, ...@@ -4357,13 +4363,15 @@ bool DocumentContentOperationsManager::CopyImpl( SwPaM& rPam, SwPosition& rPos,
if( aInsPos == pEnd->nNode ) if( aInsPos == pEnd->nNode )
{ {
SwNodeIndex aSaveIdx( aInsPos, -1 ); SwNodeIndex aSaveIdx( aInsPos, -1 );
CopyWithFlyInFly( aRg, 0,aInsPos, &rPam, bMakeNewFrms, false ); CopyWithFlyInFly( aRg, 0, aInsPos, &rPam, bMakeNewFrms,
false, false, bHandledStartNode );
++aSaveIdx; ++aSaveIdx;
pEnd->nNode = aSaveIdx; pEnd->nNode = aSaveIdx;
pEnd->nContent.Assign( aSaveIdx.GetNode().GetTxtNode(), 0 ); pEnd->nContent.Assign( aSaveIdx.GetNode().GetTxtNode(), 0 );
} }
else else
CopyWithFlyInFly( aRg, pEnd->nContent.GetIndex(), aInsPos, &rPam, bMakeNewFrms, false ); CopyWithFlyInFly( aRg, pEnd->nContent.GetIndex(), aInsPos, &rPam,
bMakeNewFrms, false, false, bHandledStartNode );
bCopyBookmarks = false; bCopyBookmarks = false;
......
...@@ -943,7 +943,6 @@ void SwDoc::Append( const SwDoc& rSource, sal_uInt16 nStartPageNumber, ...@@ -943,7 +943,6 @@ void SwDoc::Append( const SwDoc& rSource, sal_uInt16 nStartPageNumber,
SwPageDesc* pTargetPageDesc, bool bDeletePrevious ) SwPageDesc* pTargetPageDesc, bool bDeletePrevious )
{ {
// GetEndOfExtras + 1 = StartOfContent == no content node! // GetEndOfExtras + 1 = StartOfContent == no content node!
// this ensures, that we have at least two nodes in the SwPaM.
// @see IDocumentContentOperations::CopyRange // @see IDocumentContentOperations::CopyRange
SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 ); SwNodeIndex aSourceIdx( rSource.GetNodes().GetEndOfExtras(), 1 );
SwNodeIndex aSourceEndIdx( rSource.GetNodes().GetEndOfContent(), -1 ); SwNodeIndex aSourceEndIdx( rSource.GetNodes().GetEndOfContent(), -1 );
......
...@@ -106,11 +106,13 @@ public: ...@@ -106,11 +106,13 @@ public:
const SwPaM* pCopiedPaM = NULL, const SwPaM* pCopiedPaM = NULL,
bool bMakeNewFrms = true, bool bMakeNewFrms = true,
bool bDelRedlines = true, bool bDelRedlines = true,
bool bCopyFlyAtFly = false ) const; bool bCopyFlyAtFly = false,
const bool bMergedFirstNode = false ) const;
void CopyFlyInFlyImpl( const SwNodeRange& rRg, void CopyFlyInFlyImpl( const SwNodeRange& rRg,
const sal_Int32 nEndContentIndex, const sal_Int32 nEndContentIndex,
const SwNodeIndex& rStartIdx, const SwNodeIndex& rStartIdx,
const bool bCopyFlyAtFly = false ) const; const bool bCopyFlyAtFly = false,
const bool bMergedFirstNode = false ) const;
/// Parameters for _Rst and lcl_SetTxtFmtColl /// Parameters for _Rst and lcl_SetTxtFmtColl
//originallyfrom docfmt.cxx //originallyfrom docfmt.cxx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment