Index: core/dom/node.js =================================================================== --- core/dom/node.js (revision 3504) +++ core/dom/node.js (working copy) @@ -271,9 +271,6 @@ getNextSourceNode : function( startFromSibling, nodeType, guard ) { - var node = ( !startFromSibling && this.getFirst && this.getFirst() ) || this.getNext(), - parent; - // If "guard" is a node, transform it in a function. if ( guard && !guard.call ) { @@ -284,6 +281,18 @@ }; } + var node = ( !startFromSibling && this.getFirst && this.getFirst() ), + parent; + + // Guarding when we're skipping the current element( no children or 'startFromSibling' ). + // send the 'moving out' signal even we don't actually dive into. + if ( !node ) + { + if ( this.type == CKEDITOR.NODE_ELEMENT && guard && guard( this, true ) === false ) + return null; + node = this.getNext(); + } + while ( !node && ( parent = ( parent || this ).getParent() ) ) { // The guard check sends the "true" paramenter to indicate that @@ -308,9 +317,6 @@ getPreviousSourceNode : function( startFromSibling, nodeType, guard ) { - var node = ( !startFromSibling && this.getLast && this.getLast() ) || this.getPrevious(), - parent; - if ( guard && !guard.call ) { var guardNode = guard; @@ -320,6 +326,18 @@ }; } + var node = ( !startFromSibling && this.getLast && this.getLast() ), + parent; + + // Guarding when we're skipping the current element( no children or 'startFromSibling' ). + // send the 'moving out' signal even we don't actually dive into. + if ( !node ) + { + if ( this.type == CKEDITOR.NODE_ELEMENT && guard && guard( this, true ) === false ) + return null; + node = this.getPrevious(); + } + while ( !node && ( parent = ( parent || this ).getParent() ) ) { // The guard check sends the "true" paramenter to indicate that Index: tests/core/dom/walker.html =================================================================== --- tests/core/dom/walker.html (revision 3515) +++ tests/core/dom/walker.html (working copy) @@ -301,15 +301,42 @@ assertNodesList( [ '
', ' test', '', '', 'simple', 'a ', 'This is ' ], nodes );
},
+ /**
+ * Test walker stop at empty endContainer.
+ */
+ test_stopGuard : function()
+ {
+ var node = doc.getById( 'playground' );
+ node.setHtml( 'afterEnd' );
+ var endContainer = node.getFirst();
+ var range = new CKEDITOR.dom.range( doc );
+ range.selectNodeContents( node );
+ range.setEndAt( endContainer, CKEDITOR.POSITION_AFTER_START );
+ var walker = new CKEDITOR.dom.walker( range );
+ var nodes = [];
+
+ walker.evaluator = function( node )
+ {
+ nodes.push( node );
+ return true;
+ };
+
+ while ( ( node = walker.next() ) )
+ { /*jsl:pass*/ }
+
+ assertNodesList( [ '' ], nodes );
+
+ },
name : document.title
};
})() );
+//window.onload = tc.test_stopGuard;
//]]>
-