Index: _whatsnew.html
===================================================================
--- _whatsnew.html	(revision 1791)
+++ _whatsnew.html	(working copy)
@@ -267,6 +267,9 @@
 			&lt;PRE&gt; block.</li>
 		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1627">#1627</a>] Samples
 			failed to load from local filesystem in IE7.</li>
+		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1229">#1229</a>] Converting
+			multiple contiguous paragraphs to Formatted will now be merged into a single 
+			&lt;PRE&gt; block.</li>
 	</ul>
 	<p>
 		<a href="_whatsnew_history.html">See previous versions history</a>
Index: editor/_source/classes/fckstyle.js
===================================================================
--- editor/_source/classes/fckstyle.js	(revision 1791)
+++ editor/_source/classes/fckstyle.js	(working copy)
@@ -836,6 +836,55 @@
 		return newBlock ;
 	},
 
+	// The currentBlock must not be moved or deleted from the DOM tree.
+	// This guarantees the FCKDomRangeIterator in _ApplyBlockStyle would not
+	// get lost at the next iteration.
+	_CheckAndMergePre : function( previousBlock, currentBlock )
+	{
+		// Check if the next block in HTML equals the next <PRE> block generated.
+		if ( FCKDomTools.GetNextSourceElement( previousBlock, true, null, null, true ) != currentBlock )
+			return ;
+
+		// Merge the upper <PRE> block's content into the lower <PRE>
+		// block.
+		// Remove the upper <PRE> block.
+		//
+		// Another thing to be careful here is that currentBlock might
+		// contain a '\n' at the beginning, and previousBlock might
+		// contain a '\n' towards the end. These new lines are not
+		// normally displayed but they become visible after merging.
+		currentBlock.innerHTML = previousBlock.innerHTML.replace( /\n$/, '' ) + '\n\n' +
+			currentBlock.innerHTML.replace( /^\n/, '' ) ;
+		FCKDomTools.RemoveNode( previousBlock ) ;
+	},
+
+	_CheckAndSplitPre : function( doc, previousBlock )
+	{
+		var lastNewBlock = null ;
+		for ( var j = 0 ; j < previousBlock.childNodes.length ; j++ )
+		{
+			var cursor = previousBlock.childNodes[j] ;
+
+			// If we have two <BR>s, and they're not at the beginning or the end,
+			// then we'll split up the contents following them into another block.
+			if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != previousBlock.childNodes.length - 2
+					&& cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) )
+			{
+				FCKDomTools.RemoveNode( cursor.nextSibling ) ;
+				FCKDomTools.RemoveNode( cursor ) ;
+				j-- ;	// restart at current index at next iteration
+				lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || previousBlock, doc.createElement( previousBlock.nodeName ) ) ;
+				continue ;
+			}
+
+			if ( lastNewBlock )
+			{
+				FCKDomTools.MoveNode( cursor, lastNewBlock ) ;
+				j-- ;	// restart at current index at next iteration
+			}
+		}
+	},
+
 	/**
 	 * Apply an inline style to a FCKDomRange.
 	 *
@@ -857,8 +906,8 @@
 		var block ;
 		var doc = range.Window.document ;
 
-		var preBlocks = [] ;
-		var convertedPreBlocks = [] ;
+		var previousPreBlock ;
+		var previousConvertedPreBlock ;
 
 		while( ( block = iterator.GetNextParagraph() ) )		// Only one =
 		{
@@ -869,65 +918,35 @@
 			var newBlockIsPre = newBlock.nodeName.IEquals( 'pre' ) ;
 			var blockIsPre = block.nodeName.IEquals( 'pre' ) ;
 			if ( newBlockIsPre && !blockIsPre )
-			{
 				newBlock = this._ToPre( doc, block, newBlock ) ;
-				preBlocks.push( newBlock ) ;
-			}
 			else if ( !newBlockIsPre && blockIsPre )
-			{
 				newBlock = this._FromPre( doc, block, newBlock ) ;
-				convertedPreBlocks.push( newBlock ) ;
-			}
 			else	// Convering from a regular block to another regular block.
 				FCKDomTools.MoveChildren( block, newBlock ) ;
 
 			// Replace the current block.
 			block.parentNode.insertBefore( newBlock, block ) ;
 			FCKDomTools.RemoveNode( block ) ;
-		}
 
-		// Merge adjacent <PRE> blocks for #1229.
-		for ( var i = 0 ; i < preBlocks.length - 1 ; i++ )
-		{
-			// Check if the next block in HTML equals the next <PRE> block generated.
-			if ( FCKDomTools.GetNextSourceElement( preBlocks[i], true, [], [], true ) != preBlocks[i+1] )
-				continue ;
-
-			// Merge the upper <PRE> block's content into the lower <PRE> block.
-			// Remove the upper <PRE> block.
-			preBlocks[i+1].innerHTML = preBlocks[i].innerHTML + '\n\n' + preBlocks[i+1].innerHTML ;
-			FCKDomTools.RemoveNode( preBlocks[i] ) ;
-		}
-
-		// Split converted <PRE> blocks for #1229.
-		for ( var i = 0 ; i < convertedPreBlocks.length ; i++ )
-		{
-			var currentBlock = convertedPreBlocks[i] ;
-			var lastNewBlock = null ;
-			for ( var j = 0 ; j < currentBlock.childNodes.length ; j++ )
+			// Split and merge processed PRE blocks after they're
+			// placed in document.
+			if ( newBlockIsPre && !blockIsPre )
 			{
-				var cursor = currentBlock.childNodes[j] ;
-
-				// If we have two <BR>s, and they're not at the beginning or the end,
-				// then we'll split up the contents following them into another block.
-				if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != currentBlock.childNodes.length - 2
-						&& cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) )
-				{
-					FCKDomTools.RemoveNode( cursor.nextSibling ) ;
-					FCKDomTools.RemoveNode( cursor ) ;
-					j-- ;	// restart at current index at next iteration
-					lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || currentBlock, doc.createElement( currentBlock.nodeName ) ) ;
-					continue ;
-				}
-
-				if ( lastNewBlock )
-				{
-					FCKDomTools.MoveNode( cursor, lastNewBlock ) ;
-					j-- ;	// restart at current index at next iteration
-				}
+				if ( previousPreBlock )
+					this._CheckAndMergePre( previousPreBlock, newBlock ) ;
+				previousPreBlock = newBlock ;
 			}
+			else if ( !newBlockIsPre && blockIsPre )
+			{
+				if ( previousConvertedPreBlock )
+					this._CheckAndSplitPre( doc, previousConvertedPreBlock ) ;
+				previousConvertedPreBlock = newBlock ;
+			}
 		}
 
+		if ( previousConvertedPreBlock )
+			this._CheckAndSplitPre( doc, previousConvertedPreBlock ) ;
+
 		// Re-select the original range.
 		if ( selectIt )
 			range.SelectBookmark( bookmark ) ;
