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