X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fdomiterator%2Fplugin.js;h=f68f7c09d3533b72bba37a4f69a5364872a160c4;hp=5c092bba559b7efa8509ac066373cc56f1cb7ae6;hb=2f22c0c38f17e75be5541089076885442aaa2377;hpb=e73319a12b56100b29ef456fd74114fe5519e01c diff --git a/_source/plugins/domiterator/plugin.js b/_source/plugins/domiterator/plugin.js index 5c092bb..f68f7c0 100644 --- a/_source/plugins/domiterator/plugin.js +++ b/_source/plugins/domiterator/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -63,7 +63,7 @@ CKEDITOR.plugins.add( 'domiterator' ); var removePreviousBr, removeLastBr; // This is the first iteration. Let's initialize it. - if ( !this._.lastNode ) + if ( !this._.started ) { range = this.range.clone(); @@ -76,44 +76,49 @@ CKEDITOR.plugins.add( 'domiterator' ); range.enlarge( this.forceBrBreak && !touchPre || !this.enlargeBr ? CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS ); - var walker = new CKEDITOR.dom.walker( range ), - ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true ); - // Avoid anchor inside bookmark inner text. - walker.evaluator = ignoreBookmarkTextEvaluator; - this._.nextNode = walker.next(); - // TODO: It's better to have walker.reset() used here. - walker = new CKEDITOR.dom.walker( range ); - walker.evaluator = ignoreBookmarkTextEvaluator; - var lastNode = walker.previous(); - this._.lastNode = lastNode.getNextSourceNode( true ); - - // We may have an empty text node at the end of block due to [3770]. - // If that node is the lastNode, it would cause our logic to leak to the - // next block.(#3887) - if ( this._.lastNode && - this._.lastNode.type == CKEDITOR.NODE_TEXT && - !CKEDITOR.tools.trim( this._.lastNode.getText() ) && - this._.lastNode.getParent().isBlockBoundary() ) + if ( !range.collapsed ) { - var testRange = new CKEDITOR.dom.range( range.document ); - testRange.moveToPosition( this._.lastNode, CKEDITOR.POSITION_AFTER_END ); - if ( testRange.checkEndOfBlock() ) + var walker = new CKEDITOR.dom.walker( range.clone() ), + ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true ); + // Avoid anchor inside bookmark inner text. + walker.evaluator = ignoreBookmarkTextEvaluator; + this._.nextNode = walker.next(); + // TODO: It's better to have walker.reset() used here. + walker = new CKEDITOR.dom.walker( range.clone() ); + walker.evaluator = ignoreBookmarkTextEvaluator; + var lastNode = walker.previous(); + this._.lastNode = lastNode.getNextSourceNode( true ); + + // We may have an empty text node at the end of block due to [3770]. + // If that node is the lastNode, it would cause our logic to leak to the + // next block.(#3887) + if ( this._.lastNode && + this._.lastNode.type == CKEDITOR.NODE_TEXT && + !CKEDITOR.tools.trim( this._.lastNode.getText() ) && + this._.lastNode.getParent().isBlockBoundary() ) { - var path = new CKEDITOR.dom.elementPath( testRange.endContainer ); - var lastBlock = path.block || path.blockLimit; - this._.lastNode = lastBlock.getNextSourceNode( true ); + var testRange = new CKEDITOR.dom.range( range.document ); + testRange.moveToPosition( this._.lastNode, CKEDITOR.POSITION_AFTER_END ); + if ( testRange.checkEndOfBlock() ) + { + var path = new CKEDITOR.dom.elementPath( testRange.endContainer ); + var lastBlock = path.block || path.blockLimit; + this._.lastNode = lastBlock.getNextSourceNode( true ); + } } - } - // Probably the document end is reached, we need a marker node. - if ( !this._.lastNode ) - { - this._.lastNode = this._.docEndMarker = range.document.createText( '' ); - this._.lastNode.insertAfter( lastNode ); + // Probably the document end is reached, we need a marker node. + if ( !this._.lastNode ) + { + this._.lastNode = this._.docEndMarker = range.document.createText( '' ); + this._.lastNode.insertAfter( lastNode ); + } + + // Let's reuse this variable. + range = null; } - // Let's reuse this variable. - range = null; + this._.started = 1; } var currentNode = this._.nextNode; @@ -279,7 +284,7 @@ CKEDITOR.plugins.add( 'domiterator' ); range.insertNode( block ); removePreviousBr = removeLastBr = true; - } + } else if ( block.getName() != 'li' ) { // If the range doesn't includes the entire contents of the @@ -346,7 +351,7 @@ CKEDITOR.plugins.add( 'domiterator' ); // next interation. if ( !this._.nextNode ) { - this._.nextNode = ( isLast || block.equals( lastNode ) ) ? null : + this._.nextNode = ( isLast || block.equals( lastNode ) || !lastNode ) ? null : getNextSourceNode( block, 1, lastNode ); }