Skip to content

Commit

Permalink
Merge branch 't/13599b'
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Jasiun committed Aug 20, 2015
2 parents 89d54d8 + e7b615f commit 06362a8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CKEditor 4 Changelog
Fixed Issues:

* [#13142](http://dev.ckeditor.com/ticket/13142): [Edge] Fixed: CTRL+A, backspace results in an empty div.
* [#13599](http://dev.ckeditor.com/ticket/13599): Fixed: Cross-editor D&D of inline widget ends up in error/artifacts.

## CKEditor 4.5.3

Expand Down
4 changes: 3 additions & 1 deletion plugins/clipboard/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,9 @@
// Create a dataTransfer object and save it globally.
editable.attachListener( editor, 'dragstart', function( evt ) {
clipboard.initDragDataTransfer( evt, editor );
}, null, null, 2 );

editable.attachListener( editor, 'dragstart', function() {
// Save drag range globally for cross editor D&D.
var dragRange = clipboard.dragRange = editor.getSelection().getRanges()[ 0 ];

Expand All @@ -1296,7 +1298,7 @@
clipboard.dragStartContainerChildCount = dragRange ? getContainerChildCount( dragRange.startContainer ) : null;
clipboard.dragEndContainerChildCount = dragRange ? getContainerChildCount( dragRange.endContainer ) : null;
}
}, null, null, 2 );
}, null, null, 100 );

// -------------- DRAGEND --------------
// Clean up on dragend.
Expand Down
9 changes: 8 additions & 1 deletion plugins/widget/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2372,10 +2372,17 @@
editor.on( 'drop', function( evt ) {
var dataTransfer = evt.data.dataTransfer,
id = dataTransfer.getData( 'cke/widget-id' ),
transferType = dataTransfer.getTransferType( editor ),
dragRange = editor.createRange(),
sourceWidget;

if ( id === '' || dataTransfer.getTransferType( editor ) != CKEDITOR.DATA_TRANSFER_INTERNAL ) {
// Disable cross-editor drag & drop for widgets - #13599.
if ( id !== '' && transferType === CKEDITOR.DATA_TRANSFER_CROSS_EDITORS ) {
evt.cancel();
return;
}

if ( id === '' || transferType != CKEDITOR.DATA_TRANSFER_INTERNAL ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/clipboard/manual/draganddrop.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Drop scenarios:

**Note:** internal D&D is the most complex operation because editor have to handle two ranges at the same time.

**Note:** that block widget D&D works only internally in one editor.
**Note:** that widget (both block and inline) D&D works only internally in one editor.
34 changes: 34 additions & 0 deletions tests/plugins/widget/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,40 @@
} );
},

'test drop - cross-editor drop': function() {
var editor = this.editor;

this.editorBot.setData( '<p class="x">foo</p><p><b>x<span data-widget="testwidget" id="w1">foo</span>x</b></p>', function() {
var evt = { data: bender.tools.mockDropEvent() },
range = editor.createRange(),
dropCalled = false,
dropNotCancelled = false;

CKEDITOR.plugins.clipboard.initDragDataTransfer( evt );
evt.data.dataTransfer.setData( 'cke/widget-id', getWidgetById( editor, 'w1' ).id );

// Not really a cross-editor drop. We're just making it appear so.
evt.data.dataTransfer.sourceEditor = {};

range.setStart( editor.document.findOne( '.x' ).getFirst(), 1 );
range.collapse( true );
evt.data.testRange = range;

editor.once( 'drop', function() {
dropCalled = true;
}, null, null, 1 );

editor.once( 'drop', function() {
dropNotCancelled = true;
}, null, null, 999 );

drop( editor, evt.data, range );

assert.areSame( true, dropCalled, 'the drop event should have been called' );
assert.areSame( false, dropNotCancelled, 'the drop event should have been cancelled' );
} );
},

'test drop - wrong widget id': function() {
var editor = this.editor;

Expand Down

0 comments on commit 06362a8

Please sign in to comment.