Index: /FCKeditor/branches/features/custom_list_command/editor/_source/classes/fckdomrange.js
===================================================================
--- /FCKeditor/branches/features/custom_list_command/editor/_source/classes/fckdomrange.js	(revision 795)
+++ /FCKeditor/branches/features/custom_list_command/editor/_source/classes/fckdomrange.js	(revision 796)
@@ -917,6 +917,6 @@
 		var startContainer = this._Range.startContainer ;
 		var endContainer = this._Range.endContainer ;
-		var startNode = startContainer.nodeType == 1 ? startContainer.childNodes[this._Range.startOffset] : startContainer ;
-		var endNode = endContainer.nodeType == 1 ? endContainer.childNodes[this._Range.endOffset] : endContainer ;
+		var startNode = startContainer.lastNode ? startContainer.childNodes[this._Range.startOffset] : startContainer ;
+		var endNode = endContainer.lastNode ? endContainer.childNodes[this._Range.endOffset] : endContainer ;
 		return { 
 			'startContainer' : startContainer, 
Index: /FCKeditor/branches/features/custom_list_command/editor/_source/commandclasses/fcklistcommands.js
===================================================================
--- /FCKeditor/branches/features/custom_list_command/editor/_source/commandclasses/fcklistcommands.js	(revision 795)
+++ /FCKeditor/branches/features/custom_list_command/editor/_source/commandclasses/fcklistcommands.js	(revision 796)
@@ -66,4 +66,12 @@
 				endNode = FCKDomTools.GetNextSourceNode( endNode ) ;
 				var shallowestNode = startNode ;
+				var inlineShallowestNode = startNode ;
+				itemRanges[i] = {
+					'range' : currentItem ,
+					'start' : startNode,
+					'end' : endNode,
+					'top' : null,
+					'topDepth' : null ,
+				} ;
 				while ( currentNode != endNode )
 				{
@@ -83,61 +91,67 @@
 						FCKDomTools.SetNodeMarker( markerObj, unmarkedNodes[j], '_FCKDepthCounter', 
 							       topDepth + 1 + j ) ;
-					}
-					if ( ancestor._FCKDepthCounter < shallowestNode._FCKDepthCounter )
-						shallowestNode = ancestor ;
+						/*
+						FCKDebug.Output( unmarkedNodes[j].nodeName + ":" + unmarkedNodes[j]._FCKDepthCounter + ":" + 
+						    ( topDepth + 1 + j ) ) ;
+						*/
+					}
+					if ( currentNode._FCKDepthCounter < shallowestNode._FCKDepthCounter )
+						shallowestNode = currentNode ;
 					currentNode = FCKDomTools.GetNextSourceNode( currentNode ) ;
 				}
-
+				itemRanges[i].top = shallowestNode ;
+				itemRanges[i].topDepth = shallowestNode._FCKDepthCounter ;
+			}
+
+			for ( var i = 0 ; i < itemRanges.length ; i++ )
+			{
 				// Create the document fragment for the item.
 				var currentFragment = selectionRange.Window.document.createDocumentFragment() ;
 				itemDocFragments.push( currentFragment ) ;
-
-				// For each DOM node within this range:
-				// If the node's depth is the same as the shallowest node, then simply add the node to the document fragment.
-				// Else, recreate or reuse all the node's parents up to the shallowest node's level
-				// 	- If the parents can be reused, just add the node or the appropriate subtree to the parent.
-				//	- If no parent can be reused, reproduce the whole subtree and keep a record for all nodes of the subtree
-				// 		so that those nodes can be reused as parent nodes later.
+				var startNode = itemRanges[i].start ;
+				var endNode = itemRanges[i].end ;
+				var itemMarkers = {} ;
+
 				currentNode = startNode ;
 				while ( currentNode != endNode )
 				{
-					var nextNode = null ;
-					if ( currentNode.lastChild )
-						nextNode = FCKDomTools.GetNextSourceNode( currentNode.lastChild ) ;
-					else
-						nextNode = FCKDomTools.GetNextSourceNode( currentNode ) ;
-					if ( currentNode._FCKDepthCounter > shallowestNode._FCKDepthCounter )
-					{
-						var ancestor = currentNode.parentNode ;
-						var lastAncestor = null ;
-						while ( ancestor._FCKDepthCounter >= shallowestNode._FCKDepthCounter && 
-								ancestor._FCKImageNode == undefined )
+					var ancestor = currentNode ;
+					var previousImage = null ;
+					var currentImage = null ;
+					while ( ancestor._FCKDepthCounter >= itemRanges[i].topDepth ) 
+					{
+						if ( ancestor._FCKCurrentImage )
+							currentImage = ancestor._FCKCurrentImage ;
+						else
 						{
-							var imageNode = ancestor.cloneNode( false ) ;
-							FCKDomTools.SetNodeMarker( markerObj, ancestor, '_FCKImageNode', imageNode ) ;
-							if ( lastAncestor && lastAncestor._FCKImageNode )
-								imageNode.appendChild( lastAncestor._FCKImageNode ) ;
-							lastAncestor = ancestor ;
-							ancestor = ancestor.parentNode ;
+							/*
+							FCKDebug.Output( i + ":" + ancestor.nodeName + ":" + currentNode.nodeName + 
+									":" + (ancestor == currentNode) ) ;
+							*/
+							currentImage = ancestor.cloneNode( false ) ;
+							FCKDomTools.SetNodeMarker( itemMarkers, ancestor, '_FCKCurrentImage', currentImage ) ;
 						}
-						var parentNode = currentNode.parentNode ;
-						FCKDomTools.SetNodeMarker( markerObj, currentNode, '_FCKPreviousParent', parentNode ) ;
-						FCKDomTools.SetNodeMarker( markerObj, currentNode, '_FCKPreviousNextSibling', 
-								currentNode.nextSibling ) ;
-						parentNode.removeChild( currentNode ) ;
-						parentNode._FCKImageNode.appendChild( currentNode ) ;
-						currentFragment.appendChild( ancestor._FCKImageNode ) ;
-					}
-					else
-					{
-						FCKDomTools.SetNodeMarker( markerObj, currentNode, '_FCKPreviousParent', currentNode ) ;
-						FCKDomTools.SetNodeMarker( markerObj, currentNode, '_FCKPreviousNextSibling',
-							       currentNode.nextSibling ) ;
-						currentNode.parentNode.removeChild( currentNode ) ;
-						currentFragment.appendChild( currentNode ) ;
-					}
-					currentNode = nextNode ;
-				}
-			}
+						if ( previousImage )
+							currentImage.appendChild( previousImage ) ;
+						previousImage = currentImage ;
+						ancestor = ancestor.parentNode ;
+					}
+					if ( currentImage.parentNode == null )
+						currentFragment.appendChild( currentImage ) ;
+					currentNode = FCKDomTools.GetNextSourceNode( currentNode ) ;
+				}
+
+				FCKDomTools.ClearNodeMarkers( itemMarkers ) ;
+			}
+
+			// For testing and debug use
+			/*
+			for ( var i = 0 ; i < itemDocFragments.length ; i++ )
+			{
+				var tmp = selectionRange.Window.document.createElement( 'div' ) ;
+				tmp.appendChild( itemDocFragments[i] ) ;
+				FCKDebug.Output( tmp.innerHTML ) ;
+			}
+			*/
 
 			// Now we should have a list of document fragments corresponding to individual list items.
@@ -154,12 +168,39 @@
 			// 	Look for the highest level item in the list, and insert the list right before the highest level
 			//	item's original nextSibling.
+
+			/*
+			// Array containing information of list blocks that needs to be inserted -
+			// The list node themselves, and where they should be inserted to
 			var listBlocks = [] ;
+			
+			// Get the common parents of the range and read the nearest common parent's tree depth.
+			var startTerminal = itemRanges[0].GetTerminalNodes().startNode ;
+			var endTerminal = itemRanges[itemRanges.length - 1].GetTerminalNodes().endNode ;
+			var nearestCommonParent = FCKTools.GetCommonParents( startTerminal, endTerminal ).pop() ;
+			var nearestParentDepth = nearestCommonParent.nodeName.IEquals( 'body' ) ? 
+				0 : nearestCommonParent._FCKDepthCounter ;
+			var currentListBlock = {
+				'node' : selectionRange.Window.document.createElement( this.TagName ),
+				'parent' : null,
+				'next' : null
+			} ;
+
 			for ( var i = 0 ; i < itemDocFragments.length ; i++ )
 			{
 				var previousParent = itemDocFragments[i].firstChild._FCKPreviousParent ;
 				var ancestor = previousParent ;
-				//while ( ancestor._FCKDepthCounter <= )
-			}
-
+				if ( currentListBlock.parent == null )
+				{
+					currentListBlock.parent = previousParent ;
+					currentListBlock.next = itemDocFragments.lastChild._FCKPreviousNextSibling ;
+				}
+				while ( ancestor._FCKDepthCounter >= nearestParentDepth )
+				{
+					if ( FCKListsLib.PathBlockLimitElements[ancestor.nodeName.toLowerCase()] )
+					{
+					}
+				}
+			}
+			*/
 
 			// Clean up all the markings
Index: /FCKeditor/branches/features/custom_list_command/editor/_source/internals/fckdomtools.js
===================================================================
--- /FCKeditor/branches/features/custom_list_command/editor/_source/internals/fckdomtools.js	(revision 795)
+++ /FCKeditor/branches/features/custom_list_command/editor/_source/internals/fckdomtools.js	(revision 796)
@@ -506,9 +506,8 @@
 		var id = String( parseInt( Math.random() * 0xfffffff, 10 ) ) ;
 		element._FCKMarkerId = id ;
-		element.attrName = value ;
+		element[attrName] = value ;
 		if ( ! markObj[id] )
-			markObj[id] = { 'element' : element, 'markers' : { attrName : value } } ;
-		else
-			markObj[id]['markers'][attrName] = value ;
+			markObj[id] = { 'element' : element, 'markers' : {} } ;
+		markObj[id]['markers'][attrName] = value ;
 	},
 
