diff --git a/CHANGES.md b/CHANGES.md index 4dc08b3e4bb..a3514c5453c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -CKEditor 4 Changelog +CKEditor 4 Changelog ==================== ## CKEditor 4.5.5 @@ -12,6 +12,7 @@ Fixed Issues: * [#13887](https://dev.ckeditor.com/ticket/13887): Fixed: Link target now supports wider ASCII character range. Thanks to [SamZiemer](https://github.com/SamZiemer)! * [#13790](https://dev.ckeditor.com/ticket/13790): Fixed: Allow for the iframe having been removed already. Thanks to [Stefan Rijnhart](https://github.com/StefanRijnhart)! * [#13803](https://dev.ckeditor.com/ticket/13803): Fixed: Allow the editor to be destroyed before being fully initialized. Thanks to [Cyril Fluck](https://github.com/cyril-sf)! +* [#13879](http://dev.ckeditor.com/ticket/13879): Fixed: Preventing [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop) event. * [#12848](http://dev.ckeditor.com/ticket/12848): Fixed: Opening find dialog in [read-only](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode will no longer throw an exception. * [#12189](http://dev.ckeditor.com/ticket/12189): Fixed: Link plugin dialog does not display subject of email links if subject parameter is not lowercase. * [#13361](http://dev.ckeditor.com/ticket/13361): Fixed: Images fail when site path includes parentheses because background-image path needs single-quotes around URL value. diff --git a/plugins/clipboard/plugin.js b/plugins/clipboard/plugin.js index 59835d1379f..03578396df4 100644 --- a/plugins/clipboard/plugin.js +++ b/plugins/clipboard/plugin.js @@ -1,4 +1,4 @@ -/** +/** * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ @@ -1340,6 +1340,11 @@ // -------------- DROP -------------- editable.attachListener( dropTarget, 'drop', function( evt ) { + // Do nothing if event was already prevented. (#13879) + if ( evt.data.$.defaultPrevented ) { + return; + } + // Cancel native drop. evt.data.preventDefault(); @@ -1364,7 +1369,7 @@ // Fire drop. fireDragEvent( evt, dragRange, dropRange ); - } ); + }, null, null, 9999 ); // Create dataTransfer or get it, if it was created before. editable.attachListener( editor, 'drop', clipboard.initDragDataTransfer, clipboard, null, 1 ); diff --git a/tests/plugins/clipboard/drop.js b/tests/plugins/clipboard/drop.js index 64b3aadde4e..0b4e43f9ad2 100644 --- a/tests/plugins/clipboard/drop.js +++ b/tests/plugins/clipboard/drop.js @@ -90,23 +90,26 @@ function drop( editor, evt, config, onDrop, onFinish ) { finishListener = function() { resume( function() { - // Drop event asserts - assert.areSame( 1, values.dropEventCounter, 'There should be always one drop.' ); - assert.isTrue( values.dropInstanceOfDataTransfer, 'On drop: dropEvt.data.dataTransfer should be instance of dataTransfer.' ); - if ( config.expectedText && isCustomDataTypesSupported ) { - assert.areSame( config.expectedText, values.dropDataText, 'On drop: text data should match.' ); - } - if ( config.expectedHtml ) { - // isInnerHtmlMatching remove space from the end of strings we compare, adding 'x' fix this problem. - assert.isInnerHtmlMatching( 'x' + config.expectedHtml + 'x', 'x' + values.dropDataHtml + 'x', 'On drop: HTML data should match.' ); - } - assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start container should match.' ); - assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start offset should match.' ); + if ( !config.expectedDropPrevented ) { + // Drop event asserts + assert.areSame( 1, values.dropEventCounter, 'There should be always one drop.' ); + + assert.isTrue( values.dropInstanceOfDataTransfer, 'On drop: dropEvt.data.dataTransfer should be instance of dataTransfer.' ); + if ( config.expectedText && isCustomDataTypesSupported ) { + assert.areSame( config.expectedText, values.dropDataText, 'On drop: text data should match.' ); + } + if ( config.expectedHtml ) { + // isInnerHtmlMatching remove space from the end of strings we compare, adding 'x' fix this problem. + assert.isInnerHtmlMatching( 'x' + config.expectedHtml + 'x', 'x' + values.dropDataHtml + 'x', 'On drop: HTML data should match.' ); + } + assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start container should match.' ); + assert.isTrue( values.dropRangeStartContainerMatch, 'On drop: drop range start offset should match.' ); - assert.isTrue( values.dropNativeEventMatch, 'On drop: native event should match.' ); - // Check that it's the mocked drop target created by the mockDropEvent(). - assert.areSame( CKEDITOR.NODE_TEXT, values.dropTarget.type, 'On drop: drop target node type should match.' ); - assert.areSame( 'targetMock', values.dropTarget.getText(), 'On drop: drop target should match.' ); + assert.isTrue( values.dropNativeEventMatch, 'On drop: native event should match.' ); + // Check that it's the mocked drop target created by the mockDropEvent(). + assert.areSame( CKEDITOR.NODE_TEXT, values.dropTarget.type, 'On drop: drop target node type should match.' ); + assert.areSame( 'targetMock', values.dropTarget.getText(), 'On drop: drop target should match.' ); + } // Paste event asserts assert.areSame( expectedBeforePasteEventCount, values.beforePasteEventCounter, 'Before paste event should be called ' + expectedBeforePasteEventCount + ' time(s).' ); @@ -630,6 +633,30 @@ var testsForMultipleEditor = { }, function() { assert.areSame( '

^foo

', bender.tools.getHtmlWithSelection( editor ), 'after drop' ); } ); + }, + + // #13879 + 'test prevent drop': function( editor, bot ) { + var evt = bender.tools.mockDropEvent(); + + // Simulate calling evt.data.preventDefault. + evt.$.defaultPrevented = true; + + bot.setHtmlWithSelection( '

^foo

' ); + editor.resetUndo(); + + drag( editor, evt ); + + drop( editor, evt, { + dropContainer: editor.editable().findOne( '.p' ).getChild( 0 ), + dropOffset: 0, + expectedPasteEventCount: 0, + expectedDropPrevented: true + }, function() { + return true; + }, function() { + assert.areSame( '

^foo

', bender.tools.getHtmlWithSelection( editor ), 'after drop' ); + } ); } }, testsForOneEditor = { diff --git a/tests/plugins/clipboard/manual/preventdrop.html b/tests/plugins/clipboard/manual/preventdrop.html new file mode 100644 index 00000000000..f6416c38e72 --- /dev/null +++ b/tests/plugins/clipboard/manual/preventdrop.html @@ -0,0 +1,36 @@ + + + +
+

Helpers

+
+ +
+ CKEditor logo +
+
+
+
+
+

Editor

+
+

I'm working!

+
+
+ diff --git a/tests/plugins/clipboard/manual/preventdrop.md b/tests/plugins/clipboard/manual/preventdrop.md new file mode 100644 index 00000000000..5068f5d63ce --- /dev/null +++ b/tests/plugins/clipboard/manual/preventdrop.md @@ -0,0 +1,9 @@ +@bender-ui: collapsed +@bender-tags: 4.5.5, tc, 13879, clipboard +@bender-ckeditor-plugins: clipboard, wysiwygarea, toolbar, image2 + +1. Drag and drop text into the editor. +2. Drag and drop image into the editor. + +**Expected:** +* Text and image aren't pasted into the editor.