Ticket #5590: 5590.patch

File 5590.patch, 3.5 KB (added by Alfonso Martínez de Lizarrondo, 13 years ago)

Proposed patch

  • _source/plugins/removeformat/plugin.js

     
    4141
    4242                                while ( ( range = iterator.getNextRange() ) )
    4343                                {
    44                                         if ( range.collapsed )
    45                                                 continue;
     44                                        if ( ! range.collapsed )
     45                                                range.enlarge( CKEDITOR.ENLARGE_ELEMENT );
    4646
    47                                         range.enlarge( CKEDITOR.ENLARGE_ELEMENT );
    48 
    4947                                        // Bookmark the range so we can re-select it after processing.
    50                                         var bookmark = range.createBookmark();
     48                                        var bookmark = range.createBookmark(),
     49                                                // The style will be applied within the bookmark boundaries.
     50                                                startNode       = bookmark.startNode,
     51                                                endNode         = bookmark.endNode,
     52                                                currentNode;
    5153
    52                                         // The style will be applied within the bookmark boundaries.
    53                                         var startNode   = bookmark.startNode,
    54                                                 endNode         = bookmark.endNode;
    55 
    5654                                        // We need to check the selection boundaries (bookmark spans) to break
    5755                                        // the code in a way that we can properly remove partially selected nodes.
    5856                                        // For example, removing a <b> style from
     
    8179                                        };
    8280
    8381                                        breakParent( startNode );
    84                                         breakParent( endNode );
     82                                        if ( endNode )
     83                                        {
     84                                                breakParent( endNode );
    8585
    86                                         // Navigate through all nodes between the bookmarks.
    87                                         var currentNode = startNode.getNextSourceNode( true, CKEDITOR.NODE_ELEMENT );
     86                                                // Navigate through all nodes between the bookmarks.
     87                                                currentNode = startNode.getNextSourceNode( true, CKEDITOR.NODE_ELEMENT );
    8888
    89                                         while ( currentNode )
    90                                         {
    91                                                 // If we have reached the end of the selection, stop looping.
    92                                                 if ( currentNode.equals( endNode ) )
    93                                                         break;
     89                                                while ( currentNode )
     90                                                {
     91                                                        // If we have reached the end of the selection, stop looping.
     92                                                        if ( currentNode.equals( endNode ) )
     93                                                                break;
    9494
    95                                                 // Cache the next node to be processed. Do it now, because
    96                                                 // currentNode may be removed.
    97                                                 var nextNode = currentNode.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT );
     95                                                        // Cache the next node to be processed. Do it now, because
     96                                                        // currentNode may be removed.
     97                                                        var nextNode = currentNode.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT );
    9898
    99                                                 // This node must not be a fake element.
    100                                                 if ( !( currentNode.getName() == 'img'
    101                                                         && currentNode.getAttribute( '_cke_realelement' ) )
    102                                                         && filter( editor, currentNode ) )
    103                                                 {
    104                                                         // Remove elements nodes that match with this style rules.
    105                                                         if ( tagsRegex.test( currentNode.getName() ) )
    106                                                                 currentNode.remove( 1 );
    107                                                         else
     99                                                        // This node must not be a fake element.
     100                                                        if ( !( currentNode.getName() == 'img'
     101                                                                && currentNode.getAttribute( '_cke_realelement' ) )
     102                                                                && filter( editor, currentNode ) )
    108103                                                        {
    109                                                                 currentNode.removeAttributes( removeAttributes );
    110                                                                 editor.fire( 'removeFormatCleanup', currentNode );
     104                                                                // Remove elements nodes that match with this style rules.
     105                                                                if ( tagsRegex.test( currentNode.getName() ) )
     106                                                                        currentNode.remove( 1 );
     107                                                                else
     108                                                                {
     109                                                                        currentNode.removeAttributes( removeAttributes );
     110                                                                        editor.fire( 'removeFormatCleanup', currentNode );
     111                                                                }
    111112                                                        }
     113
     114                                                        currentNode = nextNode;
    112115                                                }
    113 
    114                                                 currentNode = nextNode;
    115116                                        }
    116117
    117118                                        range.moveToBookmark( bookmark );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy