Skip to content

Commit

Permalink
Fixed behavior when D&D into drag range, minor change in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik authored and Piotr Jasiun committed Aug 20, 2015
1 parent 06362a8 commit d7a2c15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
40 changes: 17 additions & 23 deletions plugins/clipboard/plugin.js
Expand Up @@ -1755,34 +1755,28 @@
dropInsideDragRange =
// Must check endNode because dragRange could be collapsed in some edge cases (simulated DnD).
endNode &&
startNode.getPosition( dropNode ) == CKEDITOR.POSITION_PRECEDING &&
endNode.getPosition( dropNode ) == CKEDITOR.POSITION_FOLLOWING;
( startNode.getPosition( dropNode ) & CKEDITOR.POSITION_PRECEDING ) &&
( endNode.getPosition( dropNode ) & CKEDITOR.POSITION_FOLLOWING );

// If the drop range happens to be inside drag range change it's position to the beginning of the drag range.
if ( dropInsideDragRange ) {
// When we normally drag and drop, the selection is changed to dropRange,
// so here we simulate the same behavior.
editor.getSelection().selectRanges( [ dropRange ] );

// Remove bookmark spans.
startNode.remove();
endNode.remove();
dropNode.remove();
// We only change position of bookmark span that is connected with dropBookmark.
// dropRange will be overwritten and set to the dropBookmark later.
dropNode.insertBefore( startNode );
}
else {
// Drop range is outside drag range.
// No we can safely delete content for the drag range...
dragRange = editor.createRange();
dragRange.moveToBookmark( dragBookmark );
editable.extractHtmlFromRange( dragRange, 1 );

// ...and paste content into the drop position.
dropRange = editor.createRange();
dropRange.moveToBookmark( dropBookmark );
// No we can safely delete content for the drag range...
dragRange = editor.createRange();
dragRange.moveToBookmark( dragBookmark );
editable.extractHtmlFromRange( dragRange, 1 );

// We do not select drop range, because of may be in the place we can not set the selection
// (e.g. between blocks, in case of block widget D&D). We put range to the paste event instead.
firePasteEvents( editor, { dataTransfer: dataTransfer, method: 'drop', range: dropRange }, 1 );
}
// ...and paste content into the drop position.
dropRange = editor.createRange();
dropRange.moveToBookmark( dropBookmark );

// We do not select drop range, because of may be in the place we can not set the selection
// (e.g. between blocks, in case of block widget D&D). We put range to the paste event instead.
firePasteEvents( editor, { dataTransfer: dataTransfer, method: 'drop', range: dropRange }, 1 );

editor.fire( 'unlockSnapshot' );
},
Expand Down
4 changes: 2 additions & 2 deletions tests/tickets/13465/1.md
@@ -1,9 +1,9 @@
@bender-ui: collapsed
@bender-tags: 4.5.3, tc, widget, 13465
@bender-ckeditor-plugins: wysiwygarea, toolbar, placeholder
@bender-ckeditor-plugins: wysiwygarea, toolbar, placeholder, sourcearea

1. Drag the placeholder after or before itself.

Expected: Nothing should happen. Placeholder should be left untouched.

Unexpected: Placeholder is lost. Error is thrown.
Unexpected: Placeholder is lost. Error is thrown.

0 comments on commit d7a2c15

Please sign in to comment.