Skip to content

Commit 5c2bd9c

Browse files
committed
Merge branch 't/13400' into major
2 parents 4870adb + 6ec2bbe commit 5c2bd9c

File tree

4 files changed

+15
-48
lines changed

4 files changed

+15
-48
lines changed

core/dom/node.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,16 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
515515
* alert( parents[ 0 ].getName() + ',' + parents[ 2 ].getName() ); // 'html,p'
516516
*
517517
* @param {Boolean} [closerFirst=false] Determines the order of returned nodes.
518-
* @param {CKEDITOR.dom.node} [lastParent=null] Guard node. Nodes that are parents of `lastParent` will be ommited.
519-
* If `parent` is `null` or `parent` is not an ancestor of this node all parents will be returned.
520518
* @returns {Array} Returns an array of {@link CKEDITOR.dom.node}.
521519
*/
522-
523-
getParents: function( closerFirst, lastParent ) {
520+
getParents: function( closerFirst ) {
524521
var node = this;
525522
var parents = [];
526523

527524
do {
528525
parents[ closerFirst ? 'push' : 'unshift' ]( node );
529526
}
530-
while ( !node.equals( lastParent ) && ( node = node.getParent() ) );
527+
while ( ( node = node.getParent() ) );
531528

532529
return parents;
533530
},

plugins/widget/plugin.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
33
* For licensing, see LICENSE.md or http://ckeditor.com/license
44
*/
@@ -1253,36 +1253,26 @@
12531253
* @since 4.5
12541254
* @private
12551255
* @param {String} selector Selector to match.
1256-
* @returns {CKEDITOR.dom.node} Matched node or null if a node has not been found.
1256+
* @returns {CKEDITOR.dom.element} Matched element or `null` if a node has not been found.
12571257
*/
12581258
_findOneNotNested: function( selector ) {
1259-
var match = null,
1260-
parents;
1261-
1262-
var matchedElements = this.wrapper.find( selector );
1259+
var matchedElements = this.wrapper.find( selector ),
1260+
match,
1261+
closestWrapper;
12631262

12641263
for ( var i = 0; i < matchedElements.count(); i++ ) {
12651264
match = matchedElements.getItem( i );
1265+
closestWrapper = match.getAscendant( Widget.isDomWidgetWrapper );
12661266

1267-
parents = match.getParents( true, this.wrapper );
1268-
// Don't include wrapper element.
1269-
parents.pop();
1270-
1271-
for ( var j = 0; j < parents.length; j++ ) {
1272-
// One of parents is a widget wrapper, so this match is already a part of other widget.
1273-
if ( Widget.isDomWidgetWrapper( parents[ j ] ) ) {
1274-
match = null;
1275-
break;
1276-
}
1267+
// The closest ascendant-wrapper of this match defines to which widget
1268+
// this match belongs. If the ascendant is this widget's wrapper
1269+
// it means that the match is not nested in other widget.
1270+
if ( this.wrapper.equals( closestWrapper ) ) {
1271+
return match;
12771272
}
1278-
1279-
// The first match is a good match.
1280-
// Other matches are probably parts of other widgets instances.
1281-
if ( match != null )
1282-
break;
12831273
}
12841274

1285-
return match;
1275+
return null;
12861276
},
12871277

12881278
/**

tests/core/dom/node.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,4 @@ <h1>Title</h1>
3131

3232
text
3333

34-
</p>
35-
<div id="guardParent">
36-
<div>
37-
<span id="getParentsWithGuard"></span>
38-
</div>
39-
</div>
34+
</p>

tests/core/dom/node.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,6 @@
673673

674674
assert.areSame( 3, node.getParents().length );
675675
assert.areSame( node.getParents()[ 0 ], node.getParents( true )[ 2 ] );
676-
677-
},
678-
679-
test_getParents_guard: function() {
680-
var guard = newNode( document.getElementById( 'guardParent' ) ),
681-
node = newNode( document.getElementById( 'getParentsWithGuard' ) ),
682-
wrongParent = newNode( document.getElementById( 'remove' ) );
683-
684-
assert.areSame( 3, node.getParents( false, guard ).length );
685-
// guard element is not a parent of node - all nodes up to root are returned (+ body, html)
686-
assert.areSame( 5, node.getParents( false, wrongParent ).length );
687-
assert.areSame( node.getParents( false, guard )[ 0 ], guard );
688-
assert.areSame( node.getParents( false, guard )[ 0 ], node.getParents( true, guard )[ 2 ] );
689-
// guard and base node are the same elements - we should get only that node
690-
assert.isTrue( node.getParents( false, node )[ 0 ].equals( node ) );
691676
},
692677

693678
test_getCommonAncestor: function() {

0 commit comments

Comments
 (0)