Ticket #3256: 3256_3.patch

File 3256_3.patch, 8.7 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/domiterator/plugin.js

     
    3131                return next;
    3232        }
    3333
     34        /**
     35         *  Evaluator for skipping bookmark nodes.
     36         */
     37        function bookmarkEvaluator( node )
     38        {
     39                return !( node && node.is && node.is ( 'span' )
     40                                        && node.hasAttribute( '_fck_bookmark' )
     41                                        || !node.is && !bookmarkEvaluator( node.getParent() ) )
     42        }
     43
    3444        var iterator = function( range )
    3545        {
    3646                if ( arguments.length < 1 )
     
    6575                        {
    6676                                range = this.range.clone();
    6777                                range.enlarge( this.forceBrBreak ? CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS );
     78                               
     79                                var walker;
     80                                walker = new CKEDITOR.dom.walker( range )
     81                                // Skip bookmark nodes.
     82                                walker.evaluator = bookmarkEvaluator;   
     83                                this._.nextNode = walker.next();
    6884
    69                                 var boundary = range.getBoundaryNodes();
    70                                 this._.nextNode = boundary.startNode;
    71                                 this._.lastNode = boundary.endNode.getNextSourceNode( true );
     85                                range = range.clone();
     86                                range.collapse();
     87                                range.setEndAt( range.document.getBody(), CKEDITOR.POSITION_BEFORE_END );
     88                                walker = new CKEDITOR.dom.walker( range );
     89                                // Skip bookmark nodes.
     90                                walker.evaluator = bookmarkEvaluator;
     91                                this._.lastNode = walker.next();
     92
    7293                                // Probably the document end is reached, we need a marker node.
    7394                                if ( !this._.lastNode )
    7495                                {
     
    7394                                if ( !this._.lastNode )
    7495                                {
    7596                                                this._.lastNode = range.document.createText( '' );
    76                                                 this._.lastNode.insertAfter(  boundary.endNode );
     97                                                range.document.getBody().append( this._.lastNode );
    7798                                }
    7899
    79100                                // Let's reuse this variable.
  • _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;
    79 
    80                         while ( ( block = iterator.getNextParagraph() ) )
    81                         {
    82                                 block.removeAttribute( 'align' );
     74                                ranges = selection.getRanges();
    8375
    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, '' ) );
    8976
    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
     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() ) )
    9783                                {
    98                                         if ( this.state == CKEDITOR.TRISTATE_OFF && !this.isDefaultAlign )
    99                                                 block.setStyle( 'text-align', this.value );
     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                                        }
    10098                                        else
    101                                                 block.removeStyle( 'text-align' );
     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                                        }
    102105                                }
     106                               
    103107                        }
    104108
    105109                        editor.focus();
  • _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                        // Adding bookmark in reverse order to avoid interacting.
     874                        for ( var i = length -1 ; i  >= 0 ; i-- )
     875                                // Defer the bookmark updates later after all ranges get processed.
     876                                retval.push( ranges[ i ].createBookmark( serializable, true ) );
     877                       
     878                        // Update all ranges to reflect the changes from bookmark adding.(#3475)
     879                        for ( i = length -1 ; i >= 0 ; i-- )
     880                                ranges[ i ].moveToBookmark( retval[ i ], false );
     881                               
     882                        // Revert both back to sequenced order.
     883                        ranges.reverse();
     884                        retval.reverse();
     885                       
     886                        // Generally it's enough to just update ranges caches.
     887                        this._.cache.ranges = ranges;
    874888                        return retval;
    875889                },
    876890
     
    887901
    888902                selectBookmarks : function( bookmarks )
    889903                {
    890                         var ranges = [];
    891                         for ( var i = 0 ; i < bookmarks.length ; i++ )
     904                        var ranges = [], l = bookmarks.length;
     905
     906                        // Removing bookmarks in sequence order to avoid interacting.
     907                        for ( var i = 0 ; i < l ; i++ )
    892908                        {
    893909                                var range = new CKEDITOR.dom.range( this.document );
    894                                 range.moveToBookmark( bookmarks[i] );
     910                                range.moveToBookmark( bookmarks[ i ] );
    895911                                ranges.push( range );
    896912                        }
    897913                        this.selectRanges( ranges );
  • _source/core/dom/range.js

     
    363363                 *              must contain ids, which can be used to restore the range even
    364364                 *              when these nodes suffer mutations (like a clonation or innerHTML
    365365                 *              change).
     366                 * @param {Boolean} [deferUpdate] Whether update the range to reflect
     367                 *      the inserting of bookmark nodes or manually update it later.
    366368                 * @returns {Object} And object representing a bookmark.
    367369                 */
    368                 createBookmark : function( serializable )
     370                createBookmark : function( serializable , deferUpdate )
    369371                {
    370372                        var startNode, endNode;
    371373                        var baseId;
     
    403405                        clone.collapse( true );
    404406                        clone.insertNode( startNode );
    405407
    406                         // Update the range position.
    407                         if ( endNode )
    408                         {
    409                                 this.setStartAfter( startNode );
    410                                 this.setEndBefore( endNode );
    411                         }
    412                         else
    413                                 this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END );
    414 
    415                         return {
     408                        var retval = {
    416409                                startNode : serializable ? baseId + 'S' : startNode,
    417410                                endNode : serializable ? baseId + 'E' : endNode,
    418411                                serializable : serializable
     
    417410                                endNode : serializable ? baseId + 'E' : endNode,
    418411                                serializable : serializable
    419412                        };
     413
     414                        if ( !deferUpdate )
     415                                this.moveToBookmark( retval, false );
     416
     417                        return retval;
    420418                },
     419               
    421420
    422421                /**
    423422                 * Creates a "non intrusive" and "mutation sensible" bookmark. This
     
    512511                                is2                     : true          // It's a createBookmark2 bookmark.
    513512                        };
    514513                },
    515 
    516                 moveToBookmark : function( bookmark )
     514               
     515                /**
     516                 *  Move the range position to what indicate by the bookmark and
     517                 *  optionally remove the bookmark nodes.
     518                 *  @param {Object} bookmark Any bookmark created via
     519                 *  {@link CKEDITOR.dom.range::createBookmark} OR
     520                 *  {@link CKEDITOR.dom.range.createBookmark2} functions.
     521                 *  @param {Boolean} [dropNodes ] Whether remove the bookmark nodes after
     522                 *  move to the destination position.(defaults to be 'true')
     523                */
     524                moveToBookmark : function( bookmark, dropNodes )
    517525                {
    518526                        if ( bookmark.is2 )             // Created with createBookmark2().
    519527                        {
     
    544552                                this.setStartBefore( startNode );
    545553
    546554                                // Remove it, because it may interfere in the setEndBefore call.
    547                                 startNode.remove();
     555                                if ( dropNodes !== false )
     556                                        startNode.remove();
    548557
    549558                                // Set the range end at the bookmark end node position, or simply
    550559                                // collapse it if it is not available.
     
    551560                                if ( endNode )
    552561                                {
    553562                                        this.setEndBefore( endNode );
    554                                         endNode.remove();
     563                                        if ( dropNodes !== false )
     564                                                endNode.remove();
    555565                                }
    556566                                else
    557567                                        this.collapse( true );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy