Ticket #4881: 4881.patch

File 4881.patch, 2.7 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/clipboard/plugin.js

     
    6868        {
    6969                exec : function( editor, data )
    7070                {
     71                        this.type == 'cut' && fixCut( editor );
     72
    7173                        var success = tryToCutCopy( editor, this.type );
    7274
    7375                        if ( !success )
     
    248250                }, 0 );
    249251        }
    250252
     253        // Cutting off control type element in IE standards breaks the selection entirely. (#4881)
     254        function fixCut( editor )
     255        {
     256                if ( !CKEDITOR.env.ie || editor.document.$.compatMode == 'BackCompat' )
     257                        return;
     258
     259                var sel = editor.getSelection();
     260                var control;
     261                if( ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && ( control = sel.getSelectedElement() ) )
     262                {
     263                        var range = sel.getRanges()[ 0 ];
     264                        var dummy = editor.document.createText( '' );
     265                        dummy.insertBefore( control );
     266                        range.setStartBefore( dummy );
     267                        range.setEndAfter( control );
     268                        sel.selectRanges( [ range ] );
     269
     270                        // Clear up the fix if the paste wasn't succeeded.
     271                        setTimeout( function()
     272                        {
     273                                // Element still online?
     274                                if ( control.getParent() )
     275                                {
     276                                        dummy.remove();
     277                                        sel.selectElement( control );
     278                                }
     279                        }, 0 );
     280                }
     281        }
     282       
    251283        // Register the plugin.
    252284        CKEDITOR.plugins.add( 'clipboard',
    253285                {
     
    318350                                        body.on( ( (mode == 'text' && CKEDITOR.env.ie) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste',
    319351                                                function( evt )
    320352                                                {
    321                                                         if ( depressBeforePasteEvent )
     353                                                        if ( depressBeforeEvent )
    322354                                                                return;
    323355
    324356                                                        getClipboardData.call( editor, evt, mode, function ( data )
     
    334366                                                        } );
    335367                                                });
    336368
     369                                        body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } );
    337370                                });
    338371
    339372                                // If the "contextmenu" plugin is loaded, register the listeners.
    340373                                if ( editor.contextMenu )
    341374                                {
    342                                         var depressBeforePasteEvent;
     375                                        var depressBeforeEvent;
    343376                                        function stateFromNamedCommand( command )
    344377                                        {
    345                                                 // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste',
     378                                                // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)',
    346379                                                // guard to distinguish from the ordinary sources( either
    347380                                                // keyboard paste or execCommand ) (#4874).
    348                                                 CKEDITOR.env.ie && command == 'Paste'&& ( depressBeforePasteEvent = 1 );
     381                                                CKEDITOR.env.ie && ( depressBeforeEvent = 1 );
    349382
    350383                                                var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
    351                                                 depressBeforePasteEvent = 0;
     384                                                depressBeforeEvent = 0;
    352385                                                return retval;
    353386                                        }
    354387
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy