Ticket #8617: 8617-3.diff

File 8617-3.diff, 3.8 KB (added by fdintino, 12 years ago)
  • _source/plugins/selection/plugin.js

     
    127127                canUndo : false
    128128        };
    129129
    130         function createFillingChar( doc )
     130        function createFillingChar( doc, selection )
    131131        {
    132                 removeFillingChar( doc );
     132                removeFillingChar( doc, selection );
    133133
    134134                var fillingChar = doc.createText( '\u200B' );
    135135                doc.setCustomData( 'cke-fillingChar', fillingChar );
     
    143143        }
    144144
    145145        // Checks if a filling char has been used, eventualy removing it (#1272).
    146         function checkFillingChar( doc )
     146        function checkFillingChar( doc, selection )
    147147        {
    148148                var fillingChar = doc && getFillingChar( doc );
    149149                if ( fillingChar )
     
    151151                        // Use this flag to avoid removing the filling char right after
    152152                        // creating it.
    153153                        if ( fillingChar.getCustomData( 'ready' ) )
    154                                 removeFillingChar( doc );
     154                                removeFillingChar( doc, selection );
    155155                        else
    156156                                fillingChar.setCustomData( 'ready', 1 );
    157157                }
    158158        }
    159159
    160         function removeFillingChar( doc )
     160        function removeFillingChar( doc, selection )
    161161        {
    162162                var fillingChar = doc && doc.removeCustomData( 'cke-fillingChar' );
    163163                if ( fillingChar )
    164164                {
     165                        // Create a bookmark for the cursor so we can restore its position
     166                        // after removing the filling character.
     167                        //
     168                        // See #8617 Cursor jumps on Backspace in Chrome
     169                        // http://dev.ckeditor.com/ticket/8617
     170                        var bookmark = ( selection ) ? selection.createBookmarks() : null;
     171
    165172                        // We can't simply remove the filling node because the user
    166173                        // will actually enlarge it when typing, so we just remove the
    167174                        // invisible char from it.
    168175                        fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) );
    169                         fillingChar = 0;
     176
     177                        if ( bookmark )
     178                                selection.selectBookmarks( bookmark );                 
    170179                }
    171180        }
    172181
     
    178187                        // (#1272). Here we set the events that should invalidate that char.
    179188                        if ( CKEDITOR.env.webkit )
    180189                        {
    181                                 editor.on( 'selectionChange', function() { checkFillingChar( editor.document ); } );
    182                                 editor.on( 'beforeSetMode', function() { removeFillingChar( editor.document ); } );
     190                                editor.on( 'selectionChange', function() { checkFillingChar( editor.document, editor.getSelection() ); } );
     191                                editor.on( 'beforeSetMode', function() { removeFillingChar( editor.document, editor.getSelection() ); } );
    183192                                editor.on( 'key', function( e )
    184193                                        {
    185194                                                // Remove the filling char before some keys get
     
    191200                                                        case 37 :       // LEFT-ARROW
    192201                                                        case 39 :       // RIGHT-ARROW
    193202                                                        case 8 :        // BACKSPACE
    194                                                                 removeFillingChar( editor.document );
     203                                                                removeFillingChar( editor.document, editor.getSelection() );
    195204                                                }
    196205                                        }, null, null, 10 );
    197206
     
    14151424                                {
    14161425                                        sel.removeAllRanges();
    14171426                                        // Remove any existing filling char first.
    1418                                         CKEDITOR.env.webkit && removeFillingChar( this.document );
     1427                                        CKEDITOR.env.webkit && removeFillingChar( this.document, this );
    14191428                                }
    14201429
    14211430                                for ( var i = 0 ; i < ranges.length ; i++ )
     
    14721481                                        {
    14731482                                                // Append a zero-width space so WebKit will not try to
    14741483                                                // move the selection by itself (#1272).
    1475                                                 var fillingChar = createFillingChar( this.document );
     1484                                                var fillingChar = createFillingChar( this.document, this );
    14761485                                                range.insertNode( fillingChar ) ;
    14771486
    14781487                                                var next = fillingChar.getNext();
     
    14821491                                                // Let's remove it in this case.
    14831492                                                if ( next && !fillingChar.getPrevious() && next.type == CKEDITOR.NODE_ELEMENT && next.getName() == 'br' )
    14841493                                                {
    1485                                                         removeFillingChar( this.document );
     1494                                                        removeFillingChar( this.document, this );
    14861495                                                        range.moveToPosition( next, CKEDITOR.POSITION_BEFORE_START );
    14871496                                                }
    14881497                                                else
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy