Ticket #3136: 3136.patch

File 3136.patch, 2.5 KB (added by Martin Kou, 15 years ago)
  • _source/plugins/wysiwygarea/plugin.js

     
    3636                                isBlock = CKEDITOR.dtd.$block[ elementName ];
    3737
    3838                        var selection = this.getSelection(),
    39                                 ranges = selection.getRanges();
     39                                range = selection.getRanges().pop();
    4040
    41                         var range, clone, lastElement, bookmark;
     41                        // Remove the original contents.
     42                        range.deleteContents();
    4243
    43                         for ( var i = ranges.length - 1 ; i >= 0 ; i-- )
     44                        var toSplit;
     45
     46                        // If the new node is a block element, split the current block (if any).
     47                        if ( this.config.enterMode != 'br' && isBlock )
    4448                        {
    45                                 range = ranges[ i ];
     49                                var startPath = new CKEDITOR.dom.elementPath( range.startContainer ),
     50                                        j = 0,
     51                                        parent;
    4652
    47                                 // Remove the original contents.
    48                                 range.deleteContents();
    49 
    50                                 clone = element.clone( true );
    51 
    52                                 var toSplit;
    53 
    54                                 // If the new node is a block element, split the current block (if any).
    55                                 if ( this.config.enterMode != 'br' && isBlock )
     53                                while( ( parent = startPath.elements[ j++ ] ) && parent != startPath.blockLimit )
    5654                                {
    57                                         var startPath = new CKEDITOR.dom.elementPath( range.startContainer ),
    58                                                 j = 0,
    59                                                 parent;
     55                                        var parentName = parent.getName(),
     56                                                parentDtd = CKEDITOR.dtd[ parentName ];
    6057
    61                                         while( ( parent = startPath.elements[ j++ ] ) && parent != startPath.blockLimit )
    62                                         {
    63                                                 var parentName = parent.getName(),
    64                                                         parentDtd = CKEDITOR.dtd[ parentName ];
    65 
    66                                                 if ( parentDtd && !parentDtd[ elementName ] )
    67                                                         toSplit = parent;
    68                                         }
     58                                        if ( parentDtd && !parentDtd[ elementName ] )
     59                                                toSplit = parent;
    6960                                }
     61                        }
    7062
    71                                 // Insert the new node.
    72                                 range.insertNode( clone );
     63                        // Insert the new node.
     64                        range.insertNode( element );
    7365
    74                                 if ( toSplit )
    75                                         clone.breakParent( toSplit );
     66                        if ( toSplit )
     67                                element.breakParent( toSplit );
    7668
    77                                 // Save the last element reference so we can make the
    78                                 // selection later.
    79                                 if ( !lastElement )
    80                                         lastElement = clone;
    81                         }
     69                        range.moveToPosition( element, CKEDITOR.POSITION_AFTER_END );
    8270
    83                         range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
    84 
    85                         var next = lastElement.getNextSourceNode( true );
     71                        var next = element.getNextSourceNode( true );
    8672                        if ( next && next.type == CKEDITOR.NODE_ELEMENT )
    8773                                range.moveToElementEditStart( next );
    8874
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy