Ticket #4650: 4650.patch

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

     
    695695                        if ( cache.selectedElement !== undefined )
    696696                                return cache.selectedElement;
    697697
    698                         var node;
     698                        var node,
     699                                        type = this.getType();
    699700
    700                         if ( this.getType() == CKEDITOR.SELECTION_ELEMENT )
     701                        if ( type == CKEDITOR.SELECTION_ELEMENT )
    701702                        {
    702703                                var sel = this.getNative();
    703704
     
    715716                                        node = range.startContainer.childNodes[ range.startOffset ];
    716717                                }
    717718                        }
     719                        // Somtimes browser lies on selection type (e.g. text[<img />]), figure it
     720                        // out by further checking the range.
     721                        else if( type == CKEDITOR.SELECTION_TEXT )
     722                        {
     723                                // Bookmark the selection first since 'getEnclosedNode'
     724                                // call below could alter it.
     725                                var bookmarks = this.createBookmarks(),
     726                                                range = this.getRanges()[ 0 ];
    718727
    719                         return cache.selectedElement = ( node ? new CKEDITOR.dom.element( node ) : null );
     728                                node = range.getEnclosedNode();
     729                                this.selectBookmarks( bookmarks );
     730                        }
     731
     732                        return ( cache.selectedElement = node && node.type == CKEDITOR.NODE_ELEMENT  ? node : null );
    720733                },
    721734
    722735                lock : function()
    723736                {
    724737                        // Call all cacheable function.
    725                         this.getRanges();
    726                         this.getStartElement();
    727738                        this.getSelectedElement();
     739                        this.getStartElement();
     740                        this.getRanges();
    728741
    729742                        // The native selection is not available when locked.
    730743                        this._.cache.nativeSel = {};
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy