Ticket #7907: 7907_3.patch

File 7907_3.patch, 5.8 KB (added by Garry Yao, 12 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();
     
    214218                                else
    215219                                        return null;
    216220
     221                                block = null;
     222
    217223                                if ( listArray.length <= currentIndex || Math.max( listArray[ currentIndex ].indent, 0 ) < indentLevel )
    218224                                        break;
    219225                        }
     
    378384
    379385                listsCreated.push( listNode );
    380386
    381                 var contentBlock, listItem;
     387                var contentBlock, blockDir, listItem;
    382388
    383389                while ( listContents.length )
    384390                {
    385391                        contentBlock = listContents.shift();
    386392                        listItem = doc.createElement( 'li' );
    387393
    388                         // Preserve preformat block and heading structure when converting to list item. (#5335) (#5271)
    389                         if ( contentBlock.is( 'pre' ) || headerTagRegex.test( contentBlock.getName() ) )
     394                        // Take it off the tree to void bothering
     395                        // the direction change event.
     396                        contentBlock.remove();
     397
     398                        if ( blockDir = contentBlock.getDirection() )
     399                        {
     400                                contentBlock.removeStyle( 'direction' );
     401                                contentBlock.removeAttribute( 'dir' );
     402                        }
     403
     404                        // Preserve the block when converting to list item if:
     405                        // 1. In preformat; (#5335)
     406                        // 2. In heading structure; (#5271)
     407                        // 3. Styled or attributed. (#6461)
     408                        if ( contentBlock.is( 'pre' )
     409                                 || headerTagRegex.test( contentBlock.getName() )
     410                                 || contentBlock.hasAttributes() )
    390411                                contentBlock.appendTo( listItem );
    391412                        else
    392413                        {
    393                                 contentBlock.copyAttributes( listItem );
    394                                 // Remove direction attribute after it was merged into list root. (#7657)
    395                                 if ( listDir && contentBlock.getDirection() )
    396                                 {
    397                                         listItem.removeStyle( 'direction' );
    398                                         listItem.removeAttribute( 'dir' );
    399                                 }
    400414                                contentBlock.moveChildren( listItem );
    401415                                contentBlock.remove();
    402416                        }
     417
     418                        // Apply text direction on list item unless it's already applied on root. (#7657)
     419                        if ( blockDir && !listDir )
     420                                listItem.setAttribute( 'dir', blockDir );
    403421
    404422                        listItem.appendTo( listNode );
    405423                }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy