Ticket #3256: 3256_4.patch

File 3256_4.patch, 4.0 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/justify/plugin.js

     
    6666        justifyCommand.prototype = {
    6767                exec : function( editor )
    6868                {
    69                         var selection = editor.getSelection(),
    70                                 range = selection && selection.getRanges()[0];
    71 
    72                         if ( !range )
     69                        var selection = editor.getSelection();
     70                        if ( !selection )
    7371                                return;
    74 
     72                       
    7573                        var bookmarks = selection.createBookmarks(),
    76                                 cssClassName = this.cssClassName,
    77                                 iterator = range.createIterator(),
    78                                 block;
     74                                ranges = selection.getRanges();
    7975
    80                         while ( ( block = iterator.getNextParagraph() ) )
    81                         {
    82                                 block.removeAttribute( 'align' );
    83 
    84                                 if ( cssClassName )
    85                                 {
    86                                         // Remove any of the alignment classes from the className.
    87                                         var className = block.$.className =
    88                                                 CKEDITOR.tools.ltrim( block.$.className.replace( this.cssClassRegex, '' ) );
    89 
    90                                         // Append the desired class name.
    91                                         if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign )
    92                                                 block.addClass( cssClassName );
    93                                         else if ( !className )
    94                                                 block.removeAttribute( 'class' );
    95                                 }
    96                                 else
    97                                 {
    98                                         if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign )
    99                                                 block.setStyle( 'text-align', this.value );
    100                                         else
    101                                                 block.removeStyle( 'text-align' );
    102                                 }
    103                         }
    104 
     76
     77                        var cssClassName = this.cssClassName,
     78                                iterator,
     79                                block;
     80                        for ( var i = ranges.length-1 ; i >= 0 ; i-- ) {
     81                                iterator = ranges[ i ].createIterator();
     82                                while ( ( block = iterator.getNextParagraph() ) )
     83                                {
     84                                        block.removeAttribute( 'align' );
     85       
     86                                        if ( cssClassName )
     87                                        {
     88                                                // Remove any of the alignment classes from the className.
     89                                                var className = block.$.className =
     90                                                        CKEDITOR.tools.ltrim( block.$.className.replace( this.cssClassRegex, '' ) );
     91       
     92                                                // Append the desired class name.
     93                                                if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign )
     94                                                        block.addClass( cssClassName );
     95                                                else if ( !className )
     96                                                        block.removeAttribute( 'class' );
     97                                        }
     98                                        else
     99                                        {
     100                                                if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign )
     101                                                        block.setStyle( 'text-align', this.value );
     102                                                else
     103                                                        block.removeStyle( 'text-align' );
     104                                        }
     105                                }
     106                               
     107                        }
     108
    105109                        editor.focus();
    106110                        editor.forceNextSelectionCheck();
    107111                        selection.selectBookmarks( bookmarks );
  • _source/plugins/selection/plugin.js

     
    868868                createBookmarks : function( serializable )
    869869                {
    870870                        var retval = [],
    871                                 ranges = this.getRanges();
    872                         for ( var i = 0 ; i < ranges.length ; i++ )
    873                                 retval.push( ranges[i].createBookmark( serializable ) );
     871                                ranges = this.getRanges(),
     872                                length = ranges.length;
     873                        for ( var i = 0; i < length ; i++ )
     874                        {
     875                                // Updating the offset values for rest of ranges which have been mangled(#3256).
     876                                for ( var j = i + 1 ; j < length ; j++ )
     877                                {
     878                                        retval.push( ranges[ i ].createBookmark( serializable, true ) );
     879
     880                                        var dirtyRange = ranges[ j ];
     881                                        function updateDirtyRange( isRangeStart, isBookmarkStart )
     882                                        {
     883                                                if ( dirtyRange[ isRangeStart ?
     884                                                      'startContainer' : 'endContainer' ].equals(
     885                                                                retval[ i ][ isBookmarkStart ?
     886                                                                   'startNode' : 'endNode' ].getParent() ) )
     887                                                        dirtyRange[ isRangeStart ? 'startOffset' : 'endOffset' ]++;
     888                                        }
     889
     890                                        updateDirtyRange( false, true );
     891                                        updateDirtyRange( false, false );
     892                                        updateDirtyRange( true, true );
     893                                        updateDirtyRange( true, false );
     894                                }
     895                        }
     896
     897                        // Update ranges caches on dirty.
     898                        if ( dirtyRange )
     899                                this._.cache.ranges = ranges;
    874900                        return retval;
    875901                },
    876902
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy