X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fclipboard%2Fplugin.js;h=f3cb0c0c172a567d0ddc69b99e27496eab632105;hp=23c58bf9437ea256790919b521a4c538fec7f3dd;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1 diff --git a/_source/plugins/clipboard/plugin.js b/_source/plugins/clipboard/plugin.js index 23c58bf..f3cb0c0 100644 --- a/_source/plugins/clipboard/plugin.js +++ b/_source/plugins/clipboard/plugin.js @@ -68,6 +68,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { exec : function( editor, data ) { + this.type == 'cut' && fixCut( editor ); + var success = tryToCutCopy( editor, this.type ); if ( !success ) @@ -182,18 +184,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license range = new CKEDITOR.dom.range( doc ); // Create container to paste into - var pastebin = new CKEDITOR.dom.element( mode == 'text' ? 'textarea' : 'div', doc ); + var pastebin = new CKEDITOR.dom.element( mode == 'text' ? 'textarea' : CKEDITOR.env.webkit ? 'body' : 'div', doc ); pastebin.setAttribute( 'id', 'cke_pastebin' ); // Safari requires a filler node inside the div to have the content pasted into it. (#4882) CKEDITOR.env.webkit && pastebin.append( doc.createText( '\xa0' ) ); doc.getBody().append( pastebin ); - // It's definitely a better user experience if we make the paste-bin pretty unnoticed - // by pulling it off the screen. pastebin.setStyles( { position : 'absolute', - left : '-1000px', // Position the bin exactly at the position of the selected element // to avoid any subsequent document scroll. top : sel.getStartElement().getDocumentPosition().y + 'px', @@ -202,6 +201,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license overflow : 'hidden' }); + // It's definitely a better user experience if we make the paste-bin pretty unnoticed + // by pulling it off the screen. + pastebin.setStyle( this.config.contentsLangDirection == 'ltr' ? 'left' : 'right', '-1000px' ); + var bms = sel.createBookmarks(); // Turn off design mode temporarily before give focus to the paste bin. @@ -248,6 +251,36 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, 0 ); } + // Cutting off control type element in IE standards breaks the selection entirely. (#4881) + function fixCut( editor ) + { + if ( !CKEDITOR.env.ie || editor.document.$.compatMode == 'BackCompat' ) + return; + + var sel = editor.getSelection(); + var control; + if( ( sel.getType() == CKEDITOR.SELECTION_ELEMENT ) && ( control = sel.getSelectedElement() ) ) + { + var range = sel.getRanges()[ 0 ]; + var dummy = editor.document.createText( '' ); + dummy.insertBefore( control ); + range.setStartBefore( dummy ); + range.setEndAfter( control ); + sel.selectRanges( [ range ] ); + + // Clear up the fix if the paste wasn't succeeded. + setTimeout( function() + { + // Element still online? + if ( control.getParent() ) + { + dummy.remove(); + sel.selectElement( control ); + } + }, 0 ); + } + } + // Register the plugin. CKEDITOR.plugins.add( 'clipboard', { @@ -318,7 +351,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license body.on( ( (mode == 'text' && CKEDITOR.env.ie) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste', function( evt ) { - if ( depressBeforePasteEvent ) + if ( depressBeforeEvent ) return; getClipboardData.call( editor, evt, mode, function ( data ) @@ -334,21 +367,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } ); }); + body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } ); }); // If the "contextmenu" plugin is loaded, register the listeners. if ( editor.contextMenu ) { - var depressBeforePasteEvent; + var depressBeforeEvent; function stateFromNamedCommand( command ) { - // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste', + // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)', // guard to distinguish from the ordinary sources( either // keyboard paste or execCommand ) (#4874). - CKEDITOR.env.ie && command == 'Paste'&& ( depressBeforePasteEvent = 1 ); + CKEDITOR.env.ie && ( depressBeforeEvent = 1 ); var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; - depressBeforePasteEvent = 0; + depressBeforeEvent = 0; return retval; }