JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4b
[ckeditor.git] / _source / plugins / list / plugin.js
index 4c728fa..0cd962f 100644 (file)
@@ -67,7 +67,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                },\r
 \r
                // Convert our internal representation of a list back to a DOM forest.\r
-               arrayToList : function( listArray, database, baseIndex, paragraphMode )\r
+               arrayToList : function( listArray, database, baseIndex, paragraphMode, dir )\r
                {\r
                        if ( !baseIndex )\r
                                baseIndex = 0;\r
@@ -109,8 +109,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        else\r
                                        {\r
                                                // Create completely new blocks here, attributes are dropped.\r
-                                               if ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' )\r
+                                               if ( dir || ( paragraphMode != CKEDITOR.ENTER_BR && item.grandparent.getName() != 'td' ) )\r
+                                               {\r
                                                        currentListItem = doc.createElement( paragraphName );\r
+                                                       if ( dir )\r
+                                                               currentListItem.setAttribute( 'dir', dir );\r
+                                               }\r
                                                else\r
                                                        currentListItem = new CKEDITOR.dom.documentFragment( doc );\r
                                        }\r
@@ -286,7 +290,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                // Insert the list to the DOM tree.\r
                var insertAnchor = listContents[ listContents.length - 1 ].getNext(),\r
-                       listNode = doc.createElement( this.type );\r
+                       listNode = doc.createElement( this.type ),\r
+                       dir;\r
 \r
                listsCreated.push( listNode );\r
                while ( listContents.length )\r
@@ -299,6 +304,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                contentBlock.appendTo( listItem );\r
                        else\r
                        {\r
+                               if ( contentBlock.hasAttribute( 'dir' ) )\r
+                               {\r
+                                       dir = dir || contentBlock.getAttribute( 'dir' );\r
+                                       contentBlock.removeAttribute( 'dir' );\r
+                               }\r
                                contentBlock.copyAttributes( listItem );\r
                                contentBlock.moveChildren( listItem );\r
                                contentBlock.remove();\r
@@ -310,6 +320,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        if ( !CKEDITOR.env.ie )\r
                                listItem.appendBogus();\r
                }\r
+\r
+               if ( dir )\r
+                       listNode.setAttribute( 'dir', dir );\r
+\r
                if ( insertAnchor )\r
                        listNode.insertBefore( insertAnchor );\r
                else\r
@@ -359,7 +373,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        }\r
                }\r
 \r
-               var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode );\r
+               var newList = CKEDITOR.plugins.list.arrayToList( listArray, database, null, editor.config.enterMode,\r
+                       groupObj.root.getAttribute( 'dir' ) );\r
 \r
                // Compensate <br> before/after the list node if the surrounds are non-blocks.(#3836)\r
                var docFragment = newList.listNode, boundaryNode, siblingNode;\r
@@ -391,7 +406,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        var doc = editor.document,\r
                                selection = editor.getSelection(),\r
-                               ranges = selection && selection.getRanges();\r
+                               ranges = selection && selection.getRanges( true );\r
 \r
                        // There should be at least one selected range.\r
                        if ( !ranges || ranges.length < 1 )\r
@@ -439,11 +454,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // Group the blocks up because there are many cases where multiple lists have to be created,\r
                        // or multiple lists have to be cancelled.\r
                        var listGroups = [],\r
-                               database = {};\r
+                               database = {},\r
+                               rangeIterator = ranges.createIterator(),\r
+                               index = 0;\r
 \r
-                       while ( ranges.length > 0 )\r
+                       while ( ( range = rangeIterator.getNextRange() ) && ++index )\r
                        {\r
-                               range = ranges.shift();\r
+                               var boundaryNodes = range.getBoundaryNodes(),\r
+                                       startNode = boundaryNodes.startNode,\r
+                                       endNode = boundaryNodes.endNode;\r
+\r
+                               if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.getName() == 'td' )\r
+                                       range.setStartAt( boundaryNodes.startNode, CKEDITOR.POSITION_AFTER_START );\r
+\r
+                               if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.getName() == 'td' )\r
+                                       range.setEndAt( boundaryNodes.endNode, CKEDITOR.POSITION_BEFORE_END );\r
+\r
                                var iterator = range.createIterator(),\r
                                        block;\r
 \r
@@ -451,6 +477,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                while ( ( block = iterator.getNextParagraph() ) )\r
                                {\r
+                                       // Avoid duplicate blocks get processed across ranges.\r
+                                       if( block.getCustomData( 'list_block' ) )\r
+                                               continue;\r
+                                       else\r
+                                               CKEDITOR.dom.element.setMarker( database, block, 'list_block', 1 );\r
+\r
                                        var path = new CKEDITOR.dom.elementPath( block ),\r
                                                pathElements = path.elements,\r
                                                pathElementsCount = pathElements.length,\r
@@ -470,7 +502,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        // no longer be valid. Since paragraphs after the list\r
                                                        // should belong to a different group of paragraphs before\r
                                                        // the list. (Bug #1309)\r
-                                                       blockLimit.removeCustomData( 'list_group_object' );\r
+                                                       blockLimit.removeCustomData( 'list_group_object_' + index );\r
 \r
                                                        var groupObj = element.getCustomData( 'list_group_object' );\r
                                                        if ( groupObj )\r
@@ -489,14 +521,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( processedFlag )\r
                                                continue;\r
 \r
-                                       // No list ancestor? Group by block limit.\r
+                                       // No list ancestor? Group by block limit, but don't mix contents from different ranges.\r
                                        var root = blockLimit;\r
-                                       if ( root.getCustomData( 'list_group_object' ) )\r
-                                               root.getCustomData( 'list_group_object' ).contents.push( block );\r
+                                       if ( root.getCustomData( 'list_group_object_' + index ) )\r
+                                               root.getCustomData( 'list_group_object_' + index ).contents.push( block );\r
                                        else\r
                                        {\r
                                                groupObj = { root : root, contents : [ block ] };\r
-                                               CKEDITOR.dom.element.setMarker( database, root, 'list_group_object', groupObj );\r
+                                               CKEDITOR.dom.element.setMarker( database, root, 'list_group_object_' + index, groupObj );\r
                                                listGroups.push( groupObj );\r
                                        }\r
                                }\r
@@ -530,7 +562,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        var sibling = listNode[ rtl ?\r
                                                'getPrevious' : 'getNext' ]( CKEDITOR.dom.walker.whitespaces( true ) );\r
                                        if ( sibling && sibling.getName &&\r
-                                            sibling.getName() == listCommand.type )\r
+                                                sibling.getName() == listCommand.type )\r
                                        {\r
                                                sibling.remove();\r
                                                // Move children order by merge direction.(#3820)\r