X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Frangelist.js;h=f29cc5f844381c47f2781427525c5b51dd85401b;hp=9c12e48a24f76518c4db842d1c94f7aefa42956f;hb=039a051ccf3901311661022a30afd60fc38130c9;hpb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7 diff --git a/_source/core/dom/rangelist.js b/_source/core/dom/rangelist.js index 9c12e48..f29cc5f 100644 --- a/_source/core/dom/rangelist.js +++ b/_source/core/dom/rangelist.js @@ -39,7 +39,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license createIterator : function() { var rangeList = this, - bookmarks = [], + bookmark = CKEDITOR.dom.walker.bookmark(), + guard = function( node ) { return ! ( node.is && node.is( 'tr' ) ); }, + bookmarks = [], current; /** @@ -49,8 +51,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license /** * Retrieves the next range in the list. + * @param {Boolean} mergeConsequent Whether join two adjacent ranges into single, e.g. consequent table cells. */ - getNextRange : function() + getNextRange : function( mergeConsequent ) { current = current == undefined ? 0 : current + 1; @@ -65,11 +68,59 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !current ) { // Make sure bookmark correctness by reverse processing. - for ( var i = rangeList.length - 1; i > 0; i-- ) + for ( var i = rangeList.length - 1; i >= 0; i-- ) bookmarks.unshift( rangeList[ i ].createBookmark( true ) ); } - else - range.moveToBookmark( bookmarks.shift() ); + + if ( mergeConsequent ) + { + // Figure out how many ranges should be merged. + var mergeCount = 0; + while ( rangeList[ current + mergeCount + 1 ] ) + { + var doc = range.document, + found = 0, + left = doc.getById( bookmarks[ mergeCount ].endNode ), + right = doc.getById( bookmarks[ mergeCount + 1 ].startNode ), + next; + + // Check subsequent range. + while ( 1 ) + { + next = left.getNextSourceNode( false ); + if ( !right.equals( next ) ) + { + // This could be yet another bookmark or + // walking across block boundaries. + if ( bookmark( next ) || ( next.type == CKEDITOR.NODE_ELEMENT && next.isBlockBoundary() ) ) + { + left = next; + continue; + } + } + else + found = 1; + + break; + } + + if ( !found ) + break; + + mergeCount++; + } + } + + range.moveToBookmark( bookmarks.shift() ); + + var next; + // Merge ranges finally after moving to bookmarks. + while( mergeCount-- ) + { + next = rangeList[ ++current ]; + next.moveToBookmark( bookmarks.shift() ); + range.setEnd( next.endContainer, next.endOffset ); + } } return range;