Ticket #4650: 4650_2.patch

File 4650_2.patch, 5.4 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/link/plugin.js

     
    9898                // If the "contextmenu" plugin is loaded, register the listeners.
    9999                if ( editor.contextMenu )
    100100                {
    101                         editor.contextMenu.addListener( function( element, selection )
     101                        editor.contextMenu.addListener( function( startElement, selection )
    102102                                {
     103                                        var element = selection.getSelectedElement();
     104                                       
    103105                                        if ( !element )
    104106                                                return null;
    105107
  • _source/plugins/selection/plugin.js

     
    625625                                                {
    626626                                                        range.optimize();
    627627
    628                                                         // Decrease the range content to exclude particial
    629                                                         // selected node on the start which doesn't have
    630                                                         // visual impact. ( #3231 )
    631                                                         while( true )
    632                                                         {
    633                                                                 var startContainer = range.startContainer,
    634                                                                         startOffset = range.startOffset;
    635                                                                 // Limit the fix only to non-block elements.(#3950)
    636                                                                 if ( startOffset == ( startContainer.getChildCount ?
    637                                                                          startContainer.getChildCount() : startContainer.getLength() )
    638                                                                          && !startContainer.isBlockBoundary() )
    639                                                                         range.setStartAfter( startContainer );
    640                                                                 else break;
    641                                                         }
    642 
    643628                                                        node = range.startContainer;
    644629
    645630                                                        if ( node.type != CKEDITOR.NODE_ELEMENT )
     
    695680                        if ( cache.selectedElement !== undefined )
    696681                                return cache.selectedElement;
    697682
    698                         var node;
     683                        var node,
     684                        type = this.getType();
    699685
    700                         if ( this.getType() == CKEDITOR.SELECTION_ELEMENT )
     686                        if ( type == CKEDITOR.SELECTION_ELEMENT )
    701687                        {
    702688                                var sel = this.getNative();
    703689
     
    714700                                        var range = sel.getRangeAt( 0 );
    715701                                        node = range.startContainer.childNodes[ range.startOffset ];
    716702                                }
     703
     704                                node = new CKEDITOR.dom.element( node );
    717705                        }
     706                        // Somtimes browser lies on selection type (e.g. text[<img />]), figure it
     707                        // out by further checking the range.
     708                        else if ( type == CKEDITOR.SELECTION_TEXT )
     709                        {
     710                                var range = this.getRanges()[ 0 ];
     711                                range.optimize();
     712                                var selectedStartNode = range.getTouchedStartNode(),
     713                                        selectedEndNode = range.getTouchedEndNode();
    718714
    719                         return cache.selectedElement = ( node ? new CKEDITOR.dom.element( node ) : null );
     715                                if ( selectedStartNode.equals( selectedEndNode ) )
     716                                        node = selectedEndNode;
     717                        }
     718
     719                        return ( cache.selectedElement = node && node.type == CKEDITOR.NODE_ELEMENT  ? node : null );
    720720                },
    721721
    722722                lock : function()
    723723                {
    724724                        // Call all cacheable function.
    725                         this.getRanges();
    726                         this.getStartElement();
    727725                        this.getSelectedElement();
     726                        this.getStartElement();
     727                        this.getRanges();
    728728
    729729                        // The native selection is not available when locked.
    730730                        this._.cache.nativeSel = {};
  • _source/core/dom/range.js

     
    666666                },
    667667
    668668                /**
    669                  * Transforms the startContainer and endContainer properties from text
    670                  * nodes to element nodes, whenever possible. This is actually possible
    671                  * if either of the boundary containers point to a text node, and its
    672                  * offset is set to zero, or after the last char in the node.
     669                 * Perform structural changes to the range which don't have visual impacts..
     670                 * <ul>
     671                 * <li>Transforms the  start/end containers from text nodes to element nodes,
     672                 * whenever possible. This will happen if either of the boundary containers
     673                 * point to a text node, and its offset is set to zero, or after the last char in the node.</li>
     674                 * <li>Shrink either the start boundary which is at the end of  any inline elements,
     675                 * or the end boundary which is at the front of  line elements, by moving
     676                 * range container out of them util any block-level element are met.</li>
    673677                 */
    674678                optimize : function()
    675679                {
     
    682686                                        this.setStartBefore( container );
    683687                                else if ( offset >= container.getLength() )
    684688                                        this.setStartAfter( container );
     689
     690                                this.optimize();
    685691                        }
     692                        else
     693                        {
     694                                // Decrease the range content to exclude particial
     695                                // selected node on the start which doesn't have
     696                                // visual impact. ( #3231 )
     697                                while( true )
     698                                {
     699                                        // Limit the fix only to non-block elements.(#3950)
     700                                        if ( offset == container.getChildCount()
     701                                                 && !container.isBlockBoundary() )
     702                                                this.setStartAfter( container );
     703                                        else break;
    686704
     705                                        container = this.startContainer;
     706                                        offset = this.startOffset;
     707                                }
     708                        }
     709
    687710                        container = this.endContainer;
    688711                        offset = this.endOffset;
    689712
     
    693716                                        this.setEndBefore( container );
    694717                                else if ( offset >= container.getLength() )
    695718                                        this.setEndAfter( container );
     719
     720                                this.optimize();
    696721                        }
     722                        else
     723                        {
     724                                while( true )
     725                                {
     726                                        if ( offset == 0
     727                                                 && !container.isBlockBoundary() )
     728                                                this.setStartBefore( container );
     729                                        else break;
     730
     731                                        container = this.startContainer;
     732                                        offset = this.startOffset;
     733                                }
     734                        }
    697735                },
    698736
    699737                /**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy