Skip to content

Commit

Permalink
Merge branch 't/13453c'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Aug 10, 2015
2 parents 67c3355 + 808b676 commit 5386e97
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Fixed Issues:

* [#13386](http://dev.ckeditor.com/ticket/13386): [Edge] Fixed: Issues with selecting and editing images.
* [#13568](http://dev.ckeditor.com/ticket/13568): Fixed: Method [`editor.getSelectedHtml()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getSelectedHtml) returns invalid results for entire content selection.
* [#13453](http://dev.ckeditor.com/ticket/13453): Fixed: Drag&drop of a whole content of the editor throws an error.

Other Changes:

Expand Down
17 changes: 10 additions & 7 deletions core/dom/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,13 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
},

/**
* @todo
* Determines what is the position relation between this and given {@link CKEDITOR.dom.node} in the document.
* This node can be preceding ({@link CKEDITOR.POSITION_PRECEDING}) or following ({@link CKEDITOR.POSITION_FOLLOWING}) given node.
* This node also can contain ({@link CKEDITOR.POSITION_CONTAINS}) or be contained by ({@link CKEDITOR.POSITION_IS_CONTAINED}) the node.
* The function returns bitmask of constants listed above or {@link CKEDITOR.POSITION_IDENTICAL} if given node is same as this node.
*
* @param {CKEDITOR.dom.node} otherNode A node to check relation with.
* @returns {Number} Position relation between this node and given node.
*/
getPosition: function( otherNode ) {
var $ = this.$;
Expand Down Expand Up @@ -586,13 +592,10 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
addressOfOther = otherNode.getAddress(),
minLevel = Math.min( addressOfThis.length, addressOfOther.length );

// Determinate preceed/follow relationship.
for ( var i = 0; i <= minLevel - 1; i++ ) {
// Determinate preceding/following relationship.
for ( var i = 0; i < minLevel; i++ ) {
if ( addressOfThis[ i ] != addressOfOther[ i ] ) {
if ( i < minLevel )
return addressOfThis[ i ] < addressOfOther[ i ] ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING;

break;
return addressOfThis[ i ] < addressOfOther[ i ] ? CKEDITOR.POSITION_PRECEDING : CKEDITOR.POSITION_FOLLOWING;
}
}

Expand Down
54 changes: 40 additions & 14 deletions plugins/clipboard/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1736,25 +1736,51 @@
// We call isDropRangeAffectedByDragRange to test the order of ranges.
isDropRangeAffected = this.isDropRangeAffectedByDragRange( dragRange, dropRange );
if ( !isDropRangeAffected ) {
dragBookmark = dragRange.createBookmark( 1 );
dragBookmark = dragRange.createBookmark( false );
}
dropBookmark = dropRange.clone().createBookmark( 1 );
dropBookmark = dropRange.clone().createBookmark( false );
if ( isDropRangeAffected ) {
dragBookmark = dragRange.createBookmark( 1 );
dragBookmark = dragRange.createBookmark( false );
}

// Check if drop range is inside range.
// This is an edge case when we drop something on editable's margin/padding.
// That space is not treated as a part of the range we drag, so it is possible to drop there.
// When we drop, browser tries to find closest drop position and it finds it inside drag range. (#13453)
var startNode = dragBookmark.startNode,
endNode = dragBookmark.endNode,
dropNode = dropBookmark.startNode,
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;

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();
}
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 );

// 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 );
// ...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 );
// 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
21 changes: 20 additions & 1 deletion tests/plugins/clipboard/drop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* bender-tags: clipboard, 13468, 13015, 13140, 12806, 13011 */
/* bender-tags: clipboard, 13468, 13015, 13140, 12806, 13011, 13453 */
/* bender-ckeditor-plugins: toolbar,clipboard,undo */
/* bender-include: _helpers/pasting.js */

Expand Down Expand Up @@ -356,6 +356,25 @@ var testsForMultipleEditor = {
} );
},

// #13453
'test drop inside drag range aborts': function( editor ) {
var bot = bender.editorBots[ editor.name ],
evt = bender.tools.mockDropEvent();

bot.setHtmlWithSelection( '<p class="p">[Lorem <b>ipsum</b> dolor sit] amet.</p>' );
editor.resetUndo();

drag( editor, evt );

drop( editor, evt, {
dropContainer: editor.editable().findOne( 'b' ).getChild( 0 ),
dropOffset: 0,
expectedPasteEventCount: 0
}, null, function() {
assert.isInnerHtmlMatching( '<p class="p">Lorem <b>^ipsum</b> dolor sit amet.@</p>', getWithHtml( editor ), htmlMatchOpts, 'after drop' );
} );
},

// Integration test (#12806).
'test drop part of the link': function( editor ) {
var bot = bender.editorBots[ editor.name ],
Expand Down
7 changes: 7 additions & 0 deletions tests/tickets/13453/1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<textarea id="editor1">
<p>Foo bar.</p>
</textarea>

<script>
CKEDITOR.replace( 'editor1' );
</script>
14 changes: 14 additions & 0 deletions tests/tickets/13453/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@bender-tags: 4.5.2, tc, 13453
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, elementspath, justify, clipboard, floatingspace, sourcearea, htmlwriter, link

* This test to work properly requires #13465 to be fixed.

------------

1. Focus editor.
2. On a bottom bar path click `body`
3. When whole body is selected, drag and drop it soemwhere in editor.

Expected result: Nothing happened (selection disappeared).
Unexpected result: The content disappeared or other errors occured.

0 comments on commit 5386e97

Please sign in to comment.