# HG changeset patch
# User Henning Brinkmann <hbrinkm@openoffice.org>
# Date 1249645241 -7200
# Node ID 1a4515412168af0b0eb90c65fd561c89922fba53
# Parent  df52593d47895aa1fdfebb88be9568e884fb5570
#i102420# _MoveNodes: Additionally check if destination index is inside source => false
Check if current range was already handled => loop
Debug output current range

diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -34,6 +34,7 @@
 #ifdef DEBUG
 #include <iostream>
 #include <dbgoutsw.hxx>
+#include <deque>
 #endif
 
 #include <stdlib.h>
@@ -450,11 +451,15 @@
 BOOL SwNodes::_MoveNodes( const SwNodeRange& aRange, SwNodes & rNodes,
 					const SwNodeIndex& aIndex, BOOL bNewFrms )
 {
-	SwNode * pAktNode;
-	if( aIndex == 0 ||
-		( (pAktNode = &aIndex.GetNode())->GetStartNode() &&
-		  !pAktNode->StartOfSectionIndex() ))
+	if( aIndex == 0)
+        return FALSE;
+    
+	SwNode * pAktNode = &aIndex.GetNode();
+    if (pAktNode->GetStartNode() && !pAktNode->StartOfSectionIndex())
 		return FALSE;
+        
+    if (aRange.aStart <= aIndex && aRange.aEnd >= aIndex)
+        return FALSE;
 
 	SwNodeRange aRg( aRange );
 
@@ -509,15 +514,29 @@
 	USHORT nSectNdCnt = 0;
 	BOOL bSaveNewFrms = bNewFrms;
 
-    sal_uInt32 nMax = 1024;
+    typedef ::std::deque< ::std::pair<sal_uInt32,sal_uInt32> > tRanges;
+    tRanges aRanges;
 	// bis alles verschoben ist
-	while( aRg.aStart < aRg.aEnd && nMax > 0)
+	while( aRg.aStart < aRg.aEnd)
     {
-        nMax--;
+        ::std::pair<sal_uInt32, sal_uInt32> aPair(aRg.aStart.GetIndex(), aRg.aEnd.GetIndex());
+
+#ifdef DEBUG        
+        char buffer[256];
+        snprintf(buffer, sizeof(buffer), "(%ld, %ld)", aPair.first, aPair.second);
+        ::std::clog << buffer << ::std::endl;
+#endif
+        if (::std::find(aRanges.begin(), aRanges.end(), aPair) != aRanges.end())
+        {
 #ifdef DEBUG
-        ::std::clog << dbg_out(aRg) << ::std::endl;
+            ::std::clog << dbg_out(*this) << ::std::endl;
 #endif
-    
+ 
+            break;
+        }
+            
+        aRanges.push_back(aPair);
+        
 		switch( (pAktNode = &aRg.aEnd.GetNode())->GetNodeType() )
 		{
 		case ND_ENDNODE:
