From d7a2c156f92134074b06945843beda0ce2bf904b Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Mon, 17 Aug 2015 11:25:03 +0200 Subject: [PATCH] Fixed behavior when D&D into drag range, minor change in test. --- plugins/clipboard/plugin.js | 40 ++++++++++++++++--------------------- tests/tickets/13465/1.md | 4 ++-- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/plugins/clipboard/plugin.js b/plugins/clipboard/plugin.js index c553f8020fe..14b8ded46cf 100644 --- a/plugins/clipboard/plugin.js +++ b/plugins/clipboard/plugin.js @@ -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' ); }, diff --git a/tests/tickets/13465/1.md b/tests/tickets/13465/1.md index ec9ed73905c..9589fef543f 100644 --- a/tests/tickets/13465/1.md +++ b/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. \ No newline at end of file +Unexpected: Placeholder is lost. Error is thrown.