Ticket #7907: 7907_4.patch

File 7907_4.patch, 4.2 KB (added by Garry Yao, 11 years ago)
  • _source/plugins/list/plugin.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    102102                                indentLevel = Math.max( listArray[ baseIndex ].indent, 0 ),
    103103                                currentListItem = null,
    104104                                orgDir,
     105                                block,
    105106                                paragraphName = ( paragraphMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
    106107                        while ( 1 )
    107108                        {
     
    146147                                        if ( listNodeNames[ item.grandparent.getName() ] )
    147148                                                currentListItem = item.element.clone( false, true );
    148149                                        else
     150                                                currentListItem = new CKEDITOR.dom.documentFragment( doc );
     151
     152                                        // Migrate all children to the new container,
     153                                        // apply the proper text direction.
     154                                        var dirLoose = item.grandparent.getDirection( 1 ) != orgDir,
     155                                                enterBr = paragraphMode == CKEDITOR.ENTER_BR,
     156                                                li = item.element,
     157                                                className = li.getAttribute( 'class' ),
     158                                                style = li.getAttribute( 'style' );
     159
     160                                        for ( var i = 0, child, count = item.contents.length; i < count; i++ )
    149161                                        {
    150                                                 // Create completely new blocks here.
    151                                                 if ( dir || item.element.hasAttributes() || paragraphMode != CKEDITOR.ENTER_BR )
     162                                                child = item.contents[ i ];
     163
     164                                                if ( child.type == CKEDITOR.NODE_ELEMENT && child.isBlockBoundary() )
    152165                                                {
    153                                                         currentListItem = doc.createElement( paragraphName );
    154                                                         item.element.copyAttributes( currentListItem, { type:1, value:1 } );
     166                                                        // Apply direction on content blocks.
     167                                                        if ( dirLoose && !child.getDirection() )
     168                                                                child.setAttribute( 'dir', orgDir );
    155169
    156                                                         // There might be a case where there are no attributes in the element after all
    157                                                         // (i.e. when "type" or "value" are the only attributes set). In this case, if enterMode = BR,
    158                                                         // the current item should be a fragment.
    159                                                         if ( !dir && paragraphMode == CKEDITOR.ENTER_BR && !currentListItem.hasAttributes() )
    160                                                                 currentListItem = new CKEDITOR.dom.documentFragment( doc );
     170                                                        // Merge into child styles.
     171                                                        style && child.setAttribute( 'style', style + child.getAttribute( 'style' ) || '' );
     172                                                        className && child.addClass( className );
    161173                                                }
    162                                                 else
    163                                                         currentListItem = new CKEDITOR.dom.documentFragment( doc );
    164                                         }
     174                                                else if ( dirLoose || !enterBr || style || className )
     175                                                {
     176                                                        // Establish new block to hold text direction and styles.
     177                                                        if ( !block )
     178                                                        {
     179                                                                block = doc.createElement( paragraphName );
     180                                                                dirLoose && block.setAttribute( 'dir', orgDir );
     181                                                        }
    165182
    166                                         if ( currentListItem.type == CKEDITOR.NODE_ELEMENT )
    167                                         {
    168                                                 if ( item.grandparent.getDirection( 1 ) != orgDir )
    169                                                         currentListItem.setAttribute( 'dir', orgDir );
    170                                         }
     183                                                        // Copy over styles to new block;
     184                                                        style && block.setAttribute( 'style', style );
     185                                                        className && block.setAttribute( 'class', className );
     186
     187                                                        block.append( child.clone( 1, 1 ) );
     188                                                }
    171189
    172                                         for ( i = 0 ; i < item.contents.length ; i++ )
    173                                                 currentListItem.append( item.contents[i].clone( 1, 1 ) );
     190                                                currentListItem.append( block || child.clone( 1, 1 ) );
     191                                        }
    174192
    175193                                        if ( currentListItem.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT
    176194                                                 && currentIndex != listArray.length - 1 )
     
    190208                                                }
    191209                                        }
    192210
    193                                         if ( currentListItem.type == CKEDITOR.NODE_ELEMENT &&
    194                                                         currentListItem.getName() == paragraphName &&
    195                                                         currentListItem.$.firstChild )
    196                                         {
    197                                                 currentListItem.trim();
    198                                                 var firstChild = currentListItem.getFirst();
    199                                                 if ( firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.isBlockBoundary() )
    200                                                 {
    201                                                         var tmp = new CKEDITOR.dom.documentFragment( doc );
    202                                                         currentListItem.moveChildren( tmp );
    203                                                         currentListItem = tmp;
    204                                                 }
    205                                         }
    206 
    207211                                        var currentListItemName = currentListItem.$.nodeName.toLowerCase();
    208212                                        if ( !CKEDITOR.env.ie && ( currentListItemName == 'div' || currentListItemName == 'p' ) )
    209213                                                currentListItem.appendBogus();
     
    213217                                }
    214218                                else
    215219                                        return null;
     220
     221                                block = null;
    216222
    217223                                if ( listArray.length <= currentIndex || Math.max( listArray[ currentIndex ].indent, 0 ) < indentLevel )
    218224                                        break;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy