Skip to content
Permalink
Browse files

Merge branch 't/12987' into major

  • Loading branch information...
pjasiun committed Mar 2, 2015
2 parents fb71fc8 + 912e30f commit 7902a0e5f522de70f065310a10c263de79fd1ac5
@@ -178,6 +178,7 @@ CKEDITOR.dom.range = function( root ) {


range.optimizeBookmark(); range.optimizeBookmark();


var isDelete = action === 0;
var isExtract = action == 1; var isExtract = action == 1;
var isClone = action == 2; var isClone = action == 2;
var doClone = isClone || isExtract; var doClone = isClone || isExtract;
@@ -387,6 +388,11 @@ CKEDITOR.dom.range = function( root ) {
function consume( node, newParent, toStart, forceClone ) { function consume( node, newParent, toStart, forceClone ) {
var nextSibling = toStart ? node.getPrevious() : node.getNext(); var nextSibling = toStart ? node.getPrevious() : node.getNext();


// We do not clone if we are only deleting, so do nothing.
if ( forceClone && isDelete ) {
return nextSibling;
}

// If cloning, just clone it. // If cloning, just clone it.
if ( isClone || forceClone ) { if ( isClone || forceClone ) {
newParent.append( node.clone( true ), toStart ); newParent.append( node.clone( true ), toStart );
@@ -475,6 +475,21 @@
var clone = range.cloneContents(); var clone = range.cloneContents();


assert.isInnerHtmlMatching( '<h1></h1><p>foo</p><h2></h2>', clone.getHtml() ); assert.isInnerHtmlMatching( '<h1></h1><p>foo</p><h2></h2>', clone.getHtml() );
},

'test cloneContents - empty container, non-empty container': function() {
var root = doc.createElement( 'div' ),
range = new CKEDITOR.dom.range( doc );

root.setHtml( '<h1></h1><h2><br /></h2>' );
doc.getBody().append( root );

range.setStart( root.findOne( 'h1' ), 0 ); // <h1>[</h1>
range.setEnd( root.findOne( 'h2' ), 0 ); // <h2>]<br /></h2>

var clone = range.cloneContents();

assert.isInnerHtmlMatching( '<h1></h1><h2></h2>', clone.getHtml() );
} }
} ); } );
} )(); } )();
@@ -146,7 +146,7 @@
assert.isTrue( range.collapsed, 'range.collapsed' ); assert.isTrue( range.collapsed, 'range.collapsed' );
}, },


'test extractContents - mergeThen': function() { 'test deleteContents - mergeThen': function() {
var root = doc.createElement( 'div' ), var root = doc.createElement( 'div' ),
range = new CKEDITOR.dom.range( doc ); range = new CKEDITOR.dom.range( doc );


@@ -161,7 +161,7 @@
assert.isInnerHtmlMatching( '<p><b>f[]r</b></p>', bender.tools.range.getWithHtml( root, range ) ); assert.isInnerHtmlMatching( '<p><b>f[]r</b></p>', bender.tools.range.getWithHtml( root, range ) );
}, },


'test extractContents - mergeThen (nothing to merge)': function() { 'test deleteContents - mergeThen (nothing to merge)': function() {
var root = doc.createElement( 'div' ), var root = doc.createElement( 'div' ),
range = new CKEDITOR.dom.range( doc ); range = new CKEDITOR.dom.range( doc );


@@ -174,6 +174,36 @@
range.deleteContents( true ); range.deleteContents( true );


assert.isInnerHtmlMatching( '<p><b>f</b>[]<u>r</u></p>', bender.tools.range.getWithHtml( root, range ) ); assert.isInnerHtmlMatching( '<p><b>f</b>[]<u>r</u></p>', bender.tools.range.getWithHtml( root, range ) );
},

'test deleteContents - empty containers': function() {
var root = doc.createElement( 'div' ),
range = new CKEDITOR.dom.range( doc );

root.setHtml( 'x<h1></h1><p>foo</p><h2></h2>y' );
doc.getBody().append( root );

range.setStart( root.findOne( 'h1' ), 0 ); // <h1>[</h1>
range.setEnd( root.findOne( 'h2' ), 0 ); // <h2>]</h2>

range.deleteContents();

assert.isInnerHtmlMatching( 'x<h1></h1>[]<h2></h2>y', bender.tools.range.getWithHtml( root, range ) );
},

'test deleteContents - empty container, non-empty container': function() {
var root = doc.createElement( 'div' ),
range = new CKEDITOR.dom.range( doc );

root.setHtml( '<h1></h1><h2><br /></h2>' );
doc.getBody().append( root );

range.setStart( root.findOne( 'h1' ), 0 ); // <h1>[</h1>
range.setEnd( root.findOne( 'h2' ), 0 ); // <h2>]<br /></h2>

range.deleteContents();

assert.isInnerHtmlMatching( '<h1></h1>[]<h2><br /></h2>', bender.tools.range.getWithHtml( root, range ) );
} }
}; };


@@ -329,6 +329,22 @@
// We would lost empty inline elements so we add "*". // We would lost empty inline elements so we add "*".
assert.isInnerHtmlMatching( '<b>*</b><p>foo</p><b>*</b>', clone.getHtml().replace( /<b><\/b>/g, '<b>*</b>' ) ); assert.isInnerHtmlMatching( '<b>*</b><p>foo</p><b>*</b>', clone.getHtml().replace( /<b><\/b>/g, '<b>*</b>' ) );
assert.isInnerHtmlMatching( 'x<b>[]a</b>y', bender.tools.range.getWithHtml( root, range ).replace( /<b><\/b>/g, '<b>*</b>' ) ); assert.isInnerHtmlMatching( 'x<b>[]a</b>y', bender.tools.range.getWithHtml( root, range ).replace( /<b><\/b>/g, '<b>*</b>' ) );
},

'test extractContents - empty container, non-empty container': function() {
var root = doc.createElement( 'div' ),
range = new CKEDITOR.dom.range( doc );

root.setHtml( '<h1></h1><h2><br /></h2>' );
doc.getBody().append( root );

range.setStart( root.findOne( 'h1' ), 0 ); // <h1>[</h1>
range.setEnd( root.findOne( 'h2' ), 0 ); // <h2>]<br /></h2>

var clone = range.extractContents();

assert.isInnerHtmlMatching( '<h1></h1><h2></h2>', clone.getHtml() );
assert.isInnerHtmlMatching( '<h1></h1>[]<h2><br /></h2>', bender.tools.range.getWithHtml( root, range ) );
} }
}; };


0 comments on commit 7902a0e

Please sign in to comment.
You can’t perform that action at this time.