Skip to content

Commit

Permalink
Merge branch 't/12987' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Jasiun committed Mar 2, 2015
2 parents fb71fc8 + 912e30f commit 7902a0e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
6 changes: 6 additions & 0 deletions core/dom/range.js
Expand Up @@ -178,6 +178,7 @@ CKEDITOR.dom.range = function( root ) {

range.optimizeBookmark();

var isDelete = action === 0;
var isExtract = action == 1;
var isClone = action == 2;
var doClone = isClone || isExtract;
Expand Down Expand Up @@ -387,6 +388,11 @@ CKEDITOR.dom.range = function( root ) {
function consume( node, newParent, toStart, forceClone ) {
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 ( isClone || forceClone ) {
newParent.append( node.clone( true ), toStart );
Expand Down
15 changes: 15 additions & 0 deletions tests/core/dom/range/clonecontents.js
Expand Up @@ -475,6 +475,21 @@
var clone = range.cloneContents();

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() );
}
} );
} )();
34 changes: 32 additions & 2 deletions tests/core/dom/range/deletecontents.js
Expand Up @@ -146,7 +146,7 @@
assert.isTrue( range.collapsed, 'range.collapsed' );
},

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

Expand All @@ -161,7 +161,7 @@
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' ),
range = new CKEDITOR.dom.range( doc );

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

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 ) );
}
};

Expand Down
16 changes: 16 additions & 0 deletions tests/core/dom/range/extractcontents.js
Expand Up @@ -329,6 +329,22 @@
// 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( '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 ) );
}
};

Expand Down

0 comments on commit 7902a0e

Please sign in to comment.