Ticket #3240: 3240_2.patch

File 3240_2.patch, 2.6 KB (added by Garry Yao, 15 years ago)
  • _source/core/dom/node.js

     
    435435                        // Handle non element nodes (don't support contains nor sourceIndex).
    436436                        if ( this.type != CKEDITOR.NODE_ELEMENT || otherNode.type != CKEDITOR.NODE_ELEMENT )
    437437                        {
    438                                 if ( $.parentNode == $other )
     438                                if ( otherNode.isAncestorOf( this ) )
    439439                                        return CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING;
    440                                 else if ( $other.parentNode == $ )
     440                                else if ( this.isAncestorOf( otherNode ) )
    441441                                        return CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING;
    442442                                else if ( $.parentNode == $other.parentNode )
    443443                                        return this.getIndex() < otherNode.getIndex() ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING;
     
    443443                                        return this.getIndex() < otherNode.getIndex() ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING;
    444444                                else
    445445                                {
    446                                         $ = $.parentNode;
    447                                         $other = $other.parentNode;
     446                                        // It's safe here to wrapping the text node with temporary element,
     447                                        // and compare the wrapper's 'sourceIndex' instead. (#3240)
     448                                        var wrappers = [];
     449                                        function wrap( node )
     450                                        {
     451                                                var wrapper = CKEDITOR.document.createElement( 'span' );
     452                                                wrapper.insertBefore( node );
     453                                                wrapper.append( node );
     454                                                wrappers.push( wrapper );
     455                                                return wrapper.$;
     456                                        }
     457                                        function removeWrappers()
     458                                        {
     459                                                for ( var i = 0; i < wrappers.length ; i++ )
     460                                                {
     461                                                        var wrapper = wrappers[ i ];
     462                                                        wrapper.getFirst().insertAfter( wrapper );
     463                                                        wrapper.remove();
     464                                                }
     465                                        }
     466                                       
     467                                        var result =
     468                                                ( $.sourceIndex || wrap( this ).sourceIndex <
     469                                                   $other.sourceIndex || wrap( otherNode ).sourceIndex ) ?
     470                                                CKEDITOR.POSITION_PRECEDING :
     471                                                CKEDITOR.POSITION_FOLLOWING;
     472                                        removeWrappers();
     473                                        return result;
    448474                                }
    449475                        }
    450476
    451                         if ( $.contains( $other ) )
    452                                 return CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING;
    453 
    454                         if ( $other.contains( $ ) )
    455                                 return CKEDITOR.POSITION_IS_CONTAINED + CKEDITOR.POSITION_FOLLOWING;
    456 
    457477                        if ( 'sourceIndex' in $ )
    458478                        {
    459479                                return ( $.sourceIndex < 0 || $other.sourceIndex < 0 ) ? CKEDITOR.POSITION_DISCONNECTED :
     
    516536                        }
    517537                        return false;
    518538                },
     539               
     540                isAncestorOf : function( other )
     541                {
     542                        while( other && ( other = other.getParent() ) )
     543                        {
     544                                if ( this.equals( other ) )
     545                                        return true;
     546                        }
     547                        return false;
     548                },
    519549
    520550                move : function( target, toStart )
    521551                {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy