Ticket #3846: 3846.patch

File 3846.patch, 6.6 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/selection/plugin.js

     
    421421
    422422                                        if ( !sel )
    423423                                                type = CKEDITOR.SELECTION_NONE;
    424                                         else if ( sel.rangeCount == 1 )
     424                                        else if ( sel.rangeCount == 1 && !sel.getRangeAt(0).collapsed )
    425425                                        {
    426426                                                // Check if the actual selection is a control (IMG,
    427427                                                // TABLE, HR, etc...).
    428 
    429                                                 var range = sel.getRangeAt(0),
     428                                                var range = this.getRanges()[ 0 ],
    430429                                                        startContainer = range.startContainer;
    431430
    432                                                 if ( startContainer == range.endContainer
    433                                                         && startContainer.nodeType == 1
     431                                                if ( startContainer.equals( range.endContainer )
     432                                                        && startContainer.is
    434433                                                        && ( range.endOffset - range.startOffset ) == 1
    435                                                         && styleObjectElements[ startContainer.childNodes[ range.startOffset ].nodeName.toLowerCase() ] )
     434                                                        && startContainer.getChild(
     435                                                         range.startOffset ).getName() in styleObjectElements )
     436                                                        type = CKEDITOR.SELECTION_ELEMENT;
     437                                                // Webkit and Opera's element selection may leak into siblings
     438                                                // nodes.( #3846)
     439                                                else if ( CKEDITOR.env.webkit || CKEDITOR.env.opera )
    436440                                                {
    437                                                         type = CKEDITOR.SELECTION_ELEMENT;
    438                                                 }
    439                                         }
     441
     442                                                        var walkerRange = range.clone(),
     443                                                                walker = new CKEDITOR.dom.walker( walkerRange );
     444                                                        walker.guard = CKEDITOR.dom.walker.text( true, true );
     445                                                        walker.evaluator = function( node )
     446                                                        {
     447                                                                return node.is && node.getName() in styleObjectElements;
     448                                                        };
     449                                                        var selectedElement = walker.next();
     450                                                        walker.reset();
     451                                                        if ( selectedElement && selectedElement.equals( walker.previous() ) )
     452                                                        {
     453                                                                type = CKEDITOR.SELECTION_ELEMENT;
     454                                                                // Determinate the selected element now.
     455                                                                cache.selectedElement = selectedElement;
     456                                                        }
     457                                                }
     458                                        }
    440459
    441460                                        return ( cache.type = type );
    442461                                },
     
    694713                 */
    695714                getSelectedElement : function()
    696715                {
     716                        var selectionType = this.getType();
    697717                        var cache = this._.cache;
    698718                        if ( cache.selectedElement !== undefined )
    699719                                return cache.selectedElement;
    700720
    701721                        var node;
    702 
    703                         if ( this.getType() == CKEDITOR.SELECTION_ELEMENT )
     722                        if ( selectionType == CKEDITOR.SELECTION_ELEMENT )
    704723                        {
    705724                                var sel = this.getNative();
    706725
  • _source/core/dom/walker.js

     
    304304                        lastBackward : function()
    305305                        {
    306306                                return iterateToLast.call( this, true );
    307                         }
     307                        },
    308308
    309                 }
     309                        /**
     310                         * Reset walker to initial state.
     311                         */
     312                        reset : function()
     313                        {
     314                                delete this._.end;
     315                                delete this.current;
     316                        }
     317                }
    310318        });
    311319
    312320        /*
     
    389397                };
    390398        };
    391399
     400        /**
     401         * Whether the to-be-evaluated node is a text node.
     402         * @param {Boolean} ignoreEmpty Whether count empty text node.
     403         * @param {Boolean} isReject
     404         */
     405        CKEDITOR.dom.walker.text = function( ignoreEmpty, isReject )
     406        {
     407                return function( node )
     408                {
     409                        var retval = node && !node.is && ( !ignoreEmpty || node.getText().length )
     410                        return isReject ? !retval : !!retval;
     411                };
     412        };
     413
    392414})();
  • _source/tests/plugins/selection/selection.html

     
    22<html xmlns="http://www.w3.org/1999/xhtml">
    33<head>
    44        <title>Plugin: selection</title>
    5         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     5        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    66        <link rel="stylesheet" type="text/css" href="../../test.css" />
    77        <script type="text/javascript" src="../../../../ckeditor_source.js"></script>
    88        <script type="text/javascript" src="../../test.js"></script>
     
    3636                        assert.areSame( 0, $range.compareEndPoints( 'EndToEnd', $range2 ), 'EndToEnd' );
    3737                },
    3838
     39                // Test select a image surrounded by texts.
     40                test_selection_3846 : function()
     41                {
     42                        var element = doc.getById( 'testZone' );
     43                        element.setHtml( '<p>A normal image <img src="../../_assets/regular_smile.gif" id="testImage"> inside the text<\/p>' );
     44                        var image = doc.getById('testImage');
     45
     46                        doc.getSelection().selectElement( image );
     47                        var selectedElement = doc.getSelection().getSelectedElement() ;
     48                        assert.areSame( CKEDITOR.SELECTION_ELEMENT, doc.getSelection().getType() );
     49                        assert.isNotNull( selectedElement, 'The floated image hasn\'t been selected' );
     50                        assert.areSame( image.$, selectedElement.$, 'The floated image hasn\'t been selected correctly' );
     51                },
     52
     53                // Test select a float image surrounded by inline style elements.
     54                test_selection_3846_2 : function()
     55                {
     56                        var element = doc.getById( 'testZone' );
     57                        element.setHtml( '<p><b>some</b><span><img src="../../_assets/regular_smile.gif" align="left" id="testImage"></span><b>text</b><\/p>' );
     58                        var image = doc.getById('testImage');
     59
     60                        doc.getSelection().selectElement( image );
     61                        var selectedElement = doc.getSelection().getSelectedElement() ;
     62                        assert.areSame( CKEDITOR.SELECTION_ELEMENT, doc.getSelection().getType(), 'The selection type is incorrect.' );
     63                        assert.isNotNull( selectedElement, 'The floated image hasn\'t been selected' );
     64                        assert.areSame( image.$, selectedElement.$, 'The floated image hasn\'t been selected correctly' );
     65                },
    3966                name : document.title
    4067        };
    4168})());
     
    4572<body>
    4673        <p>
    4774                This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">CKEditor</a>.</p>
     75                <p>&nbsp;</p>
     76                <p>&nbsp;</p>
     77        <div id="testZone"></div>
    4878</body>
    4979</html>
  • CHANGES.html

     
    117117                <li><a href="http://dev.fckeditor.net/ticket/3887">#3887</a> : Fixed an issue in which the create
    118118                        list command may leak outside of a selected table cell and into the rest of document.</li>
    119119                <li><a href="http://dev.fckeditor.net/ticket/3916">#3916</a> : Fixed maximize does not enlarge editor width when width is set.</li>
     120                <li><a href="http://dev.fckeditor.net/ticket/3846">#3846</a> : [Safari/Chrome]Image selection broken when surrounded with texts.</li>
    120121        </ul>
    121122        <h3>
    122123                CKEditor 3.0 RC</h3>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy