X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fdomiterator%2Fplugin.js;h=be88c97eb0abe41af422a9c61507f1fd4860a294;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=22815c45e2d80622a2fc20fde5ac4433d63729d8;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/plugins/domiterator/plugin.js b/_source/plugins/domiterator/plugin.js index 22815c4..be88c97 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-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -31,7 +31,9 @@ CKEDITOR.plugins.add( 'domiterator' ); var beginWhitespaceRegex = /^[\r\n\t ]+$/, // Ignore bookmark nodes.(#3783) - bookmarkGuard = CKEDITOR.dom.walker.bookmark( false, true ); + bookmarkGuard = CKEDITOR.dom.walker.bookmark( false, true ), + whitespacesGuard = CKEDITOR.dom.walker.whitespaces( true ), + skipGuard = function( node ) { return bookmarkGuard( node ) && whitespacesGuard( node ); }; // Get a reference for the next element, bookmark nodes are skipped. function getNextSourceNode( node, startFromSibling, lastNode ) @@ -61,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(); @@ -74,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; @@ -207,7 +214,7 @@ CKEDITOR.plugins.add( 'domiterator' ); // to close the range, otherwise we include the parent within it. if ( range && !closeRange ) { - while ( !currentNode.getNext( bookmarkGuard ) && !isLast ) + while ( !currentNode.getNext( skipGuard ) && !isLast ) { var parentNode = currentNode.getParent(); @@ -215,7 +222,10 @@ CKEDITOR.plugins.add( 'domiterator' ); && !parentPre && { br : 1 } ) ) { closeRange = 1; + includeNode = 0; isLast = isLast || ( parentNode.equals( lastNode) ); + // Make sure range includes bookmarks at the end of the block. (#7359) + range.setEndAt( parentNode, CKEDITOR.POSITION_BEFORE_END ); break; } @@ -274,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 @@ -341,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 ); }