Ticket #8617: 8617_4.patch

File 8617_4.patch, 2.3 KB (added by fdintino, 12 years ago)
  • _source/plugins/selection/plugin.js

     
    162162                var fillingChar = doc && doc.removeCustomData( 'cke-fillingChar' );
    163163                if ( fillingChar )
    164164                {
     165                        var sel = doc.getSelection();
     166                        // Text selection position might get mangled by
     167                        // subsequent dom modification. #8617[1]
     168                        var bm = getFixedBookmark(doc, sel);
    165169                        // We can't simply remove the filling node because the user
    166170                        // will actually enlarge it when typing, so we just remove the
    167171                        // invisible char from it.
    168172                        fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) );
    169                         fillingChar = 0;
     173                        bm && sel.selectBookmarks( [ bm ] );
    170174                }
    171175        }
    172176
     177        function getFixedBookmark ( doc, sel )
     178        {
     179                var nativeSel = sel.getNative();
     180                if ( nativeSel.type != 'None' )
     181                {
     182                        var bm = sel.createBookmarks2()[ 0 ];
     183
     184                        if ( nativeSel.anchorNode && nativeSel.anchorNode.data )
     185                        {
     186                                var anchorFillingCharIndex = nativeSel.anchorNode.data.indexOf( '\u200B' );
     187                                if ( nativeSel.anchorOffset > anchorFillingCharIndex )
     188                                        bm.startOffset--;
     189                        }
     190
     191                        if ( nativeSel.focusNode && nativeSel.focusNode.data )
     192                        {
     193                                var focusFillingCharIndex = nativeSel.focusNode.data.indexOf( '\u200B' );
     194                                if ( !nativeSel.isCollapsed && nativeSel.focusOffset > focusFillingCharIndex )
     195                                        bm.endOffset--;
     196                        }
     197                }
     198                return bm;
     199        }
     200
    173201        CKEDITOR.plugins.add( 'selection',
    174202        {
    175203                init : function( editor )
     
    186214                                                // executed, so they'll not get blocked by it.
    187215                                                switch ( e.data.keyCode )
    188216                                                {
    189                                                         case 13 :       // ENTER
    190217                                                        case CKEDITOR.SHIFT + 13 :      // SHIFT-ENTER
    191                                                         case 37 :       // LEFT-ARROW
    192                                                         case 39 :       // RIGHT-ARROW
    193                                                         case 8 :        // BACKSPACE
     218                                                        case 13 :       // ENTER
     219                                                        case 33 :       // PAGEUP
     220                                                        case 34 :       // PAGEDOWN
     221                                                        case 35 :       // HOME
     222                                                        case 36 :       // END
     223                                                        case 37 :       // LEFT-ARROW
     224                                                        case 39 :       // RIGHT-ARROW
     225                                                        case 8 :        // BACKSPACE
     226                                                        case 45 :       // INS
     227                                                        case 46 :       // DEl
    194228                                                                removeFillingChar( editor.document );
    195229                                                }
    196230                                        }, null, null, 10 );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy