Ticket #6706: 6707_2.patch

File 6707_2.patch, 4.7 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/selection/plugin.js

     
    9090                if ( start.type == CKEDITOR.NODE_TEXT )
    9191                        return false;
    9292
     93                // Empty inline at the start of block. (#6706)
     94                if ( CKEDITOR.env.ie )
     95                {
     96                        return !CKEDITOR.tools.trim( start.getHtml() )
     97                                        && isInlineCt( start )
     98                                        && range.checkStartOfBlock()
     99                                        && !range.checkEndOfBlock();
     100                }
    93101                // 1. Empty inline element. <span>^</span>
    94102                // 2. Adjoin to inline element. <p><strong>text</strong>^</p>
    95103                // 3. The only empty block in document. <body><p>^</p></body> (#7222)
    96                 return !CKEDITOR.tools.trim( start.getHtml() ) ? isInlineCt( start ) || singletonBlock( start )
     104                else if ( CKEDITOR.env.webkit )
     105                        return !CKEDITOR.tools.trim( start.getHtml() ) ? isInlineCt( start ) || singletonBlock( start )
    97106                                : isInlineCt( start.getChild( offset - 1 ) ) || isInlineCt( start.getChild( offset ) );
     107
    98108        }
    99109
    100110        var selectAllCmd =
     
    170180                }
    171181        }
    172182
     183        function introduceFillingChar( range )
     184        {
     185                // Append a zero-width space so WebKit will not try to
     186                // move the selection by itself (#1272).
     187                var fillingChar = createFillingChar( range.document );
     188                range.insertNode( fillingChar );
     189
     190                var next = fillingChar.getNext();
     191
     192                // If the filling char is followed by a <br>, whithout
     193                // having something before it, it'll not blink.
     194                // Let's remove it in this case.
     195                if ( next && !fillingChar.getPrevious() && next.type == CKEDITOR.NODE_ELEMENT && next.getName() == 'br' )
     196                {
     197                        removeFillingChar( range.document );
     198                        range.moveToPosition( next, CKEDITOR.POSITION_BEFORE_START );
     199                }
     200                else
     201                        range.moveToPosition( fillingChar, CKEDITOR.POSITION_AFTER_END );
     202        }
     203
    173204        CKEDITOR.plugins.add( 'selection',
    174205        {
    175206                init : function( editor )
    176207                {
    177                         // On WebKit only, we need a special "filling" char on some situations
    178                         // (#1272). Here we set the events that should invalidate that char.
    179                         if ( CKEDITOR.env.webkit )
     208                        // We need a special "filling char" in some situations to make the cursor blink on collapsed selection (#1272) (#6706).
     209                        // Here we set the events that invalidate that char.
     210                        if ( CKEDITOR.env.webkit || CKEDITOR.env.ie )
    180211                        {
    181212                                editor.on( 'selectionChange', function() { checkFillingChar( editor.document ); } );
    182213                                editor.on( 'beforeSetMode', function() { removeFillingChar( editor.document ); } );
     
    205236
    206237                                        if ( fillingChar )
    207238                                        {
    208                                                 // If cursor is right blinking by side of the filler node, save it for restoring,
    209                                                 // as the following text substitution will blind it. (#7437)
    210                                                 var sel = doc.$.defaultView.getSelection();
    211                                                 if ( sel.type == 'Caret' && sel.anchorNode == fillingChar.$ )
    212                                                         resetSelection = 1;
     239                                                if ( CKEDITOR.env.webkit )
     240                                                {
     241                                                        // If cursor is right blinking by side of the filler node, save it for restoring,
     242                                                        // as the following text substitution will blind it. (#7437)
     243                                                        var sel = doc.$.defaultView.getSelection();
     244                                                        if ( sel.type == 'Caret' && sel.anchorNode == fillingChar.$ )
     245                                                                resetSelection = 1;
     246                                                }
    213247
    214248                                                fillingCharBefore = fillingChar.getText();
    215249                                                fillingChar.setText( fillingCharBefore.replace( /\u200B/g, '' ) );
     
    12801314                                        ranges.length = 1;
    12811315                                }
    12821316
    1283                                 if ( ranges[ 0 ] )
    1284                                         ranges[ 0 ].select();
     1317                                var range = ranges[ 0 ];
    12851318
     1319                                if ( range )
     1320                                {
     1321                                        removeFillingChar( this.document );
     1322                                        if ( range.collapsed && rangeRequiresFix( range ) )
     1323                                                introduceFillingChar( range );
     1324
     1325                                        range.select();
     1326                                }
     1327
    12861328                                this.reset();
    12871329                        }
    12881330                        else
     
    13521394                                                        && CKEDITOR.env.webkit
    13531395                                                        && rangeRequiresFix( range ) )
    13541396                                        {
    1355                                                 // Append a zero-width space so WebKit will not try to
    1356                                                 // move the selection by itself (#1272).
    1357                                                 var fillingChar = createFillingChar( this.document );
    1358                                                 range.insertNode( fillingChar ) ;
    1359 
    1360                                                 var next = fillingChar.getNext();
    1361 
    1362                                                 // If the filling char is followed by a <br>, whithout
    1363                                                 // having something before it, it'll not blink.
    1364                                                 // Let's remove it in this case.
    1365                                                 if ( next && !fillingChar.getPrevious() && next.type == CKEDITOR.NODE_ELEMENT && next.getName() == 'br' )
    1366                                                 {
    1367                                                         removeFillingChar( this.document );
    1368                                                         range.moveToPosition( next, CKEDITOR.POSITION_BEFORE_START );
    1369                                                 }
    1370                                                 else
    1371                                                         range.moveToPosition( fillingChar, CKEDITOR.POSITION_AFTER_END );
    1372                                         }
     1397                                                introduceFillingChar( range );
     1398                                        }
    13731399
    13741400                                        nativeRange.setStart( range.startContainer.$, range.startOffset );
    13751401
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy