Ticket #1272: 1272.patch

File 1272.patch, 4.8 KB (added by Frederico Caldeira Knabben, 13 years ago)
  • _source/core/dom/text.js

     
    6767                        return this.$.nodeValue;
    6868                },
    6969
     70                setText : function( text )
     71                {
     72                        this.$.nodeValue = text;
     73                },
     74
    7075                /**
    7176                 * Breaks this text node into two nodes at the specified offset,
    7277                 * keeping both in the tree as siblings. This node then only contains
  • _source/plugins/editingblock/plugin.js

     
    152152         */
    153153        CKEDITOR.editor.prototype.setMode = function( mode )
    154154        {
     155                this.fire( 'beforeSetMode', { newMode : mode } );
     156
    155157                var data,
    156158                        holderElement = this.getThemeSpace( 'contents' ),
    157159                        isDirty = this.checkDirty();
  • _source/plugins/selection/plugin.js

     
    9898                canUndo : false
    9999        };
    100100
     101        var fillingChar,
     102                fillingCharReady;
     103
     104        // Checks if a filling char has been used, eventualy removing it (#1272).
     105        function checkFillingChar()
     106        {
     107                if ( fillingChar )
     108                {
     109                        if ( fillingCharReady )
     110                        {
     111                                // We can't simply remove the filling node because the user
     112                                // will actually enlarge it when typing, so we just remove the
     113                                // invisible char from it.
     114                                fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) );
     115                                fillingChar = 0;
     116                        }
     117
     118                        // Use this flag to avoid removing the filling char right after
     119                        // creating it.
     120                        fillingCharReady = !fillingCharReady;
     121                }
     122        }
     123
    101124        CKEDITOR.plugins.add( 'selection',
    102125        {
    103126                init : function( editor )
    104127                {
     128                        // On WebKit only, we need a special "filling" char on some situations
     129                        // (#1272). Here we set the events that should invalidate that char.
     130                        if ( CKEDITOR.env.webkit )
     131                        {
     132                                editor.on( 'selectionChange', checkFillingChar );
     133                                editor.on( 'beforeSetMode', checkFillingChar );
     134                                editor.on( 'key', function( e )
     135                                        {
     136                                                // Remove the filling char before the left-key is
     137                                                // executed, so it'll not get blocked by it.
     138                                                if ( e.data.keyCode == 37 )
     139                                                        checkFillingChar();
     140                                        });
     141                        }
     142
    105143                        editor.on( 'contentDom', function()
    106144                                {
    107145                                        var doc = editor.document,
     
    11371175                                var sel = this.getNative();
    11381176
    11391177                                if ( ranges.length )
     1178                                {
    11401179                                        sel.removeAllRanges();
     1180                                        // Remove any existing filling char first.
     1181                                        CKEDITOR.env.webkit && checkFillingChar();
     1182                                }
    11411183
    11421184                                for ( var i = 0 ; i < ranges.length ; i++ )
    11431185                                {
     
    11871229                                                startContainer.appendText( '' );
    11881230                                        }
    11891231
     1232                                        if ( range.collapsed && CKEDITOR.env.webkit )
     1233                                        {
     1234                                                // Append a zero-width space so WebKit will not try to
     1235                                                // move the selection by itself (#1272).
     1236                                                fillingChar = new CKEDITOR.dom.text( '\u200B' );
     1237                                                range.insertNode( fillingChar ) ;
     1238                                                range.moveToPosition( fillingChar, CKEDITOR.POSITION_AFTER_END );
     1239                                        }
     1240
    11901241                                        nativeRange.setStart( startContainer.$, range.startOffset );
    11911242                                        nativeRange.setEnd( range.endContainer.$, range.endOffset );
    11921243
     
    13751426                :
    13761427                        function()
    13771428                        {
    1378                                 var startContainer = this.startContainer;
    1379 
    1380                                 // If we have a collapsed range, inside an empty element, we must add
    1381                                 // something to it, otherwise the caret will not be visible.
    1382                                 if ( this.collapsed && startContainer.type == CKEDITOR.NODE_ELEMENT && !startContainer.getChildCount() )
    1383                                         startContainer.append( new CKEDITOR.dom.text( '' ) );
    1384 
    1385                                 var nativeRange = this.document.$.createRange();
    1386                                 nativeRange.setStart( startContainer.$, this.startOffset );
    1387 
    1388                                 try
    1389                                 {
    1390                                         nativeRange.setEnd( this.endContainer.$, this.endOffset );
    1391                                 }
    1392                                 catch ( e )
    1393                                 {
    1394                                         // There is a bug in Firefox implementation (it would be too easy
    1395                                         // otherwise). The new start can't be after the end (W3C says it can).
    1396                                         // So, let's create a new range and collapse it to the desired point.
    1397                                         if ( e.toString().indexOf( 'NS_ERROR_ILLEGAL_VALUE' ) >= 0 )
    1398                                         {
    1399                                                 this.collapse( true );
    1400                                                 nativeRange.setEnd( this.endContainer.$, this.endOffset );
    1401                                         }
    1402                                         else
    1403                                                 throw( e );
    1404                                 }
    1405 
    1406                                 var selection = this.document.getSelection().getNative();
    1407                                 // getSelection() returns null in case when iframe is "display:none" in FF. (#6577)
    1408                                 if ( selection )
    1409                                 {
    1410                                         selection.removeAllRanges();
    1411                                         selection.addRange( nativeRange );
    1412                                 }
     1429                                this.document.getSelection().selectRanges( [ this ] );
    14131430                        };
    14141431} )();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy