Skip to content

Commit 239db6d

Browse files
committed
Merge branch 't/13568'
2 parents 52ebb38 + fb84f04 commit 239db6d

File tree

8 files changed

+53
-13
lines changed

8 files changed

+53
-13
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ New Features:
1010
Fixed Issues:
1111

1212
* [#13386](http://dev.ckeditor.com/ticket/13386): [Edge] Fixed: Issues with selecting and editing images.
13+
* [#13568](http://dev.ckeditor.com/ticket/13568): Fixed: Method [`editor.getSelectedHtml()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getSelectedHtml) returns invalid results for entire content selection.
1314

1415
## CKEditor 4.5.2
1516

core/dom/range.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,6 @@ CKEDITOR.dom.range = function( root ) {
310310
// The second step is to handle full selection of the content between the left branch and the right branch.
311311

312312
while ( nextSibling ) {
313-
// TODO this case and the below are exactly the same because endNode is part of endParents.
314-
// The start and end nodes are on the same level. Handle this case fully here, because it's simple.
315-
if ( nextSibling.equals( endNode ) ) {
316-
lastConnectedLevel = level;
317-
break;
318-
}
319-
320313
// We can't clone entire endParent just like we can't clone entire startParent -
321314
// - they are not fully selected with the range. Partial endParent selection
322315
// will be cloned in the next loop.
@@ -374,10 +367,18 @@ CKEDITOR.dom.range = function( root ) {
374367
}
375368

376369
levelParent = nextLevelParent;
370+
} else if ( doClone ) {
371+
// If this is "shared" node and we are in cloning mode we have to update levelParent to
372+
// reflect that we visited the node (even though we didn't process it).
373+
// If we don't do that, in next iterations nodes will be appended to wrong parent.
374+
//
375+
// We can just take first child because the algorithm guarantees
376+
// that this will be the only child on this level. (#13568)
377+
levelParent = levelParent.getChild( 0 );
377378
}
378379
}
379380

380-
// Detete or Extract.
381+
// Delete or Extract.
381382
// We need to update the range and if mergeThen was passed do it.
382383
if ( !isClone ) {
383384
mergeAndUpdate();
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<div id="playground" style="visibility:hidden"><h1 id="_H1">FCKW3CRange Test</h1><p id="_Para">This is <b id="_B">some</b> text.</p><p>Another paragraph.</p></div>
2-
<div id="editable_playground" contenteditable="true"></div>
2+
<div id="editable_playground" contenteditable="true"></div>
3+
<div id="bogus"><p>Foo bar<br /></p></div>

tests/core/dom/range/clonecontents.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,18 @@
514514
assert.areSame( root.findOne( 'div' ), range.endContainer, 'range.startContainer' );
515515
assert.areSame( 0, range.startOffset, 'range.startOffset' );
516516
assert.areSame( 1, range.endOffset, 'range.startOffset' );
517+
},
518+
519+
// #13568.
520+
'test cloneContents - bogus br': function() {
521+
var range = new CKEDITOR.dom.range( doc );
522+
range.setStart( doc.getById( 'bogus' ), 0 ); // <p>
523+
range.setEnd( doc.getById( 'bogus' ).getFirst(), 1 ); // <br /> in <p>
524+
525+
var docFrag = range.cloneContents();
526+
527+
// See: execContentsAction in range.js.
528+
assert.isInnerHtmlMatching( '<p>Foo bar</p>', docFrag.getHtml(), 'Cloned HTML' );
517529
}
518530
} );
519-
} )();
531+
} )();
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
<div id="playground" style="visibility:hidden"><h1 id="_H1">FCKW3CRange Test</h1><p id="_Para">This is <b id="_B">some</b> text.</p><p>Another paragraph.</p></div>
1+
<div id="playground" style="visibility:hidden"><h1 id="_H1">FCKW3CRange Test</h1><p id="_Para">This is <b id="_B">some</b> text.</p><p>Another paragraph.</p></div>
2+
<div id="bogus"><p>Foo bar<br /></p></div>

tests/core/dom/range/extractcontents.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,20 @@
367367
assert.areSame( playground, range.startContainer, 'range.startContainer' );
368368
assert.areSame( 1, range.startOffset, 'range.startOffset' );
369369
assert.isTrue( range.collapsed, 'range.collapsed' );
370+
},
371+
372+
// #13568.
373+
'test extractContents - bogus br': function() {
374+
var range = new CKEDITOR.dom.range( doc );
375+
range.setStart( doc.getById( 'bogus' ), 0 ); // <p>
376+
range.setEnd( doc.getById( 'bogus' ).getFirst(), 1 ); // <br /> in <p>
377+
378+
var docFrag = range.extractContents();
379+
380+
// See: execContentsAction in range.js.
381+
assert.isInnerHtmlMatching( '<p>Foo bar</p>', docFrag.getHtml(), 'Extracted HTML' );
370382
}
371383
};
372384

373385
bender.test( tests );
374-
} )();
386+
} )();

tests/core/editable/getextracthtmlfromrange.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@
198198
[ '<p><b>{a}</b>@</p>', '<b>a</b>', '<p>[]@!</p>' ],
199199
[ '<p>{a}<br />@</p>', 'a', '<p>[]<br />@</p>' ],
200200
[ '<p>{a<br />]@</p>', 'a<br />', '<p>[]@!</p>' ],
201-
[ '<div>b<p>{a@]</p>b</div>', 'a', '<div>b<p>[]@!</p>b</div>' ]
201+
[ '<div>b<p>{a@]</p>b</div>', 'a', '<div>b<p>[]@!</p>b</div>' ],
202+
// #13568.
203+
[ '<div>[<p>Foo bar@</p>]</div>', '<p>Foo bar</p>', '<div>[]@!</div>' ]
204+
202205
],
203206

204207
// #13101

tests/core/editor/getextractselectedhtml.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ bender.test( {
7878
assert.isNull( selectedHtml, 'There should be no error but null should be returns if selection contains no ranges' );
7979
},
8080

81+
// #13568.
82+
'test getSelectedHtml with possible bogus br': function() {
83+
var editor = this.editors.editor,
84+
filler = CKEDITOR.env.needsBrFiller ? '<br />' : '';
85+
bender.tools.selection.setWithHtml( editor, '[<p>Foo bar' + filler + '</p>]' );
86+
87+
assert.isInnerHtmlMatching( [ '<p>Foo bar@</p>', 'Foo bar' ], editor.getSelectedHtml( true ) );
88+
},
89+
8190
'test extractSelectedHtml': function() {
8291
var editor = this.editors.editor;
8392
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' );

0 commit comments

Comments
 (0)