Ticket #8247: 8247.patch

File 8247.patch, 4.5 KB (added by Garry Yao, 12 years ago)
  • _source/plugins/domiterator/plugin.js

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    6363                        var removePreviousBr, removeLastBr;
    6464
    6565                        // This is the first iteration. Let's initialize it.
    66                         if ( !this._.lastNode )
     66                        if ( !this._.started )
    6767                        {
    6868                                range = this.range.clone();
    6969
     
    7676                                range.enlarge( this.forceBrBreak && !touchPre || !this.enlargeBr ?
    7777                                                           CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS );
    7878
    79                                 var walker = new CKEDITOR.dom.walker( range ),
    80                                         ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true );
    81                                 // Avoid anchor inside bookmark inner text.
    82                                 walker.evaluator = ignoreBookmarkTextEvaluator;
    83                                 this._.nextNode = walker.next();
    84                                 // TODO: It's better to have walker.reset() used here.
    85                                 walker = new CKEDITOR.dom.walker( range );
    86                                 walker.evaluator = ignoreBookmarkTextEvaluator;
    87                                 var lastNode = walker.previous();
    88                                 this._.lastNode = lastNode.getNextSourceNode( true );
     79                                if ( !range.collapsed )
     80                                {
     81                                        var walker = new CKEDITOR.dom.walker( range.clone() ),
     82                                                ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true );
     83                                        // Avoid anchor inside bookmark inner text.
     84                                        walker.evaluator = ignoreBookmarkTextEvaluator;
     85                                        this._.nextNode = walker.next();
     86                                        // TODO: It's better to have walker.reset() used here.
     87                                        walker = new CKEDITOR.dom.walker( range.clone() );
     88                                        walker.evaluator = ignoreBookmarkTextEvaluator;
     89                                        var lastNode = walker.previous();
     90                                        this._.lastNode = lastNode.getNextSourceNode( true );
    8991
    90                                 // We may have an empty text node at the end of block due to [3770].
    91                                 // If that node is the lastNode, it would cause our logic to leak to the
    92                                 // next block.(#3887)
    93                                 if ( this._.lastNode &&
    94                                                 this._.lastNode.type == CKEDITOR.NODE_TEXT &&
    95                                                 !CKEDITOR.tools.trim( this._.lastNode.getText() ) &&
    96                                                 this._.lastNode.getParent().isBlockBoundary() )
    97                                 {
    98                                         var testRange = new CKEDITOR.dom.range( range.document );
    99                                         testRange.moveToPosition( this._.lastNode, CKEDITOR.POSITION_AFTER_END );
    100                                         if ( testRange.checkEndOfBlock() )
    101                                         {
    102                                                 var path = new CKEDITOR.dom.elementPath( testRange.endContainer );
    103                                                 var lastBlock = path.block || path.blockLimit;
    104                                                 this._.lastNode = lastBlock.getNextSourceNode( true );
    105                                         }
    106                                 }
     92                                        // We may have an empty text node at the end of block due to [3770].
     93                                        // If that node is the lastNode, it would cause our logic to leak to the
     94                                        // next block.(#3887)
     95                                        if ( this._.lastNode &&
     96                                                        this._.lastNode.type == CKEDITOR.NODE_TEXT &&
     97                                                        !CKEDITOR.tools.trim( this._.lastNode.getText() ) &&
     98                                                        this._.lastNode.getParent().isBlockBoundary() )
     99                                        {
     100                                                var testRange = new CKEDITOR.dom.range( range.document );
     101                                                testRange.moveToPosition( this._.lastNode, CKEDITOR.POSITION_AFTER_END );
     102                                                if ( testRange.checkEndOfBlock() )
     103                                                {
     104                                                        var path = new CKEDITOR.dom.elementPath( testRange.endContainer );
     105                                                        var lastBlock = path.block || path.blockLimit;
     106                                                        this._.lastNode = lastBlock.getNextSourceNode( true );
     107                                                }
     108                                        }
    107109
    108                                 // Probably the document end is reached, we need a marker node.
    109                                 if ( !this._.lastNode )
    110                                 {
    111                                         this._.lastNode = this._.docEndMarker = range.document.createText( '' );
    112                                         this._.lastNode.insertAfter( lastNode );
    113                                 }
     110                                        // Probably the document end is reached, we need a marker node.
     111                                        if ( !this._.lastNode )
     112                                        {
     113                                                this._.lastNode = this._.docEndMarker = range.document.createText( '' );
     114                                                this._.lastNode.insertAfter( lastNode );
     115                                        }
    114116
    115                                 // Let's reuse this variable.
    116                                 range = null;
    117                         }
     117                                        // Let's reuse this variable.
     118                                        range = null;
     119                                }
    118120
     121                                this._.started = 1;
     122                        }
     123
    119124                        var currentNode = this._.nextNode;
    120125                        lastNode = this._.lastNode;
    121126
     
    279284                                                range.insertNode( block );
    280285
    281286                                                removePreviousBr = removeLastBr = true;
    282                                         }
     287                                }
    283288                                else if ( block.getName() != 'li' )
    284289                                {
    285290                                        // If the range doesn't includes the entire contents of the
     
    346351                        // next interation.
    347352                        if ( !this._.nextNode )
    348353                        {
    349                                 this._.nextNode = ( isLast || block.equals( lastNode ) ) ? null :
     354                                this._.nextNode = ( isLast || block.equals( lastNode ) || !lastNode ) ? null :
    350355                                        getNextSourceNode( block, 1, lastNode );
    351356                        }
    352357
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy