Index: /CKEditor/branches/features/contenteditable/_source/plugins/list/plugin.js
===================================================================
--- /CKEditor/branches/features/contenteditable/_source/plugins/list/plugin.js	(revision 5599)
+++ /CKEditor/branches/features/contenteditable/_source/plugins/list/plugin.js	(revision 5600)
@@ -433,6 +433,5 @@
 			// Group the blocks up because there are many cases where multiple lists have to be created,
 			// or multiple lists have to be cancelled.
-			var listGroups = [],
-				database = {},
+			var database = {},
 				rangeIterator = ranges.createIterator(),
 				index = 0;
@@ -440,4 +439,5 @@
 			while ( ( range = rangeIterator.getNextRange() ) && ++index )
 			{
+				var listGroups = [];
 				var boundaryNodes = range.getBoundaryNodes(),
 					startNode = boundaryNodes.startNode,
@@ -506,42 +506,43 @@
 					}
 				}
-			}
-
-			// Now we have two kinds of list groups, groups rooted at a list, and groups rooted at a block limit element.
-			// We either have to build lists or remove lists, for removing a list does not makes sense when we are looking
-			// at the group that's not rooted at lists. So we have three cases to handle.
-			var listsCreated = [];
-			while ( listGroups.length > 0 )
-			{
-				groupObj = listGroups.shift();
-				if ( this.state == CKEDITOR.TRISTATE_OFF )
-				{
-					if ( listNodeNames[ groupObj.root.getName() ] )
-						changeListType.call( this, editor, groupObj, database, listsCreated );
-					else
-						createList.call( this, editor, groupObj, listsCreated );
-				}
-				else if ( this.state == CKEDITOR.TRISTATE_ON && listNodeNames[ groupObj.root.getName() ] )
-					removeList.call( this, editor, groupObj, database );
-			}
-
-			// For all new lists created, merge adjacent, same type lists.
-			for ( i = 0 ; i < listsCreated.length ; i++ )
-			{
-				listNode = listsCreated[i];
-				var mergeSibling, listCommand = this;
-				( mergeSibling = function( rtl ){
-
-					var sibling = listNode[ rtl ?
-						'getPrevious' : 'getNext' ]( CKEDITOR.dom.walker.whitespaces( true ) );
-					if ( sibling && sibling.getName &&
-					     sibling.getName() == listCommand.type )
-					{
-						sibling.remove();
-						// Move children order by merge direction.(#3820)
-						sibling.moveChildren( listNode, rtl ? true : false );
-					}
-				} )();
-				mergeSibling( true );
+
+				// Now we have two kinds of list groups, groups rooted at a list, and groups rooted at a block limit element.
+				// We either have to build lists or remove lists, for removing a list does not makes sense when we are looking
+				// at the group that's not rooted at lists. So we have three cases to handle.
+				var listsCreated = [];
+				while ( listGroups.length > 0 )
+				{
+					groupObj = listGroups.shift();
+					if ( this.state == CKEDITOR.TRISTATE_OFF )
+					{
+						if ( listNodeNames[ groupObj.root.getName() ] )
+							changeListType.call( this, editor, groupObj, database, listsCreated );
+						else
+							createList.call( this, editor, groupObj, listsCreated );
+					}
+					else if ( this.state == CKEDITOR.TRISTATE_ON && listNodeNames[ groupObj.root.getName() ] )
+						removeList.call( this, editor, groupObj, database );
+				}
+
+				// For all new lists created, merge adjacent, same type lists.
+				for ( i = 0 ; i < listsCreated.length ; i++ )
+				{
+					listNode = listsCreated[i];
+					var mergeSibling, listCommand = this;
+					( mergeSibling = function( rtl ){
+
+						var sibling = listNode[ rtl ?
+							'getPrevious' : 'getNext' ]( CKEDITOR.dom.walker.whitespaces( true ) );
+						if ( sibling && sibling.getName &&
+							 sibling.getName() == listCommand.type )
+						{
+							sibling.remove();
+							// Move children order by merge direction.(#3820)
+							sibling.moveChildren( listNode, rtl ? true : false );
+						}
+					} )();
+					mergeSibling( true );
+				}
+
 			}
 
