Skip to content

Commit 4a28dcc

Browse files
committed
Merge branch 't/11132'
2 parents bace56b + 5161c1c commit 4a28dcc

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Fixed Issues:
1111

1212
* [#11159](http://dev.ckeditor.com/ticket/11159): [Enhanced Image](http://ckeditor.com/addon/image2): Fixed buggy discovery of image dimensions in IE9 and IE10.
1313
* [#11198](http://dev.ckeditor.com/ticket/11198): Widgets: Drag handler is not fully visible when inline widget is in a heading.
14+
* [#11132](http://dev.ckeditor.com/ticket/11132): [Firefox] Fixed: Caret is lost after drag and drop of inline widget.
1415

1516
## CKEditor 4.3
1617

plugins/widget/plugin.js

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,16 +1666,33 @@
16661666
return element.hasAttribute( 'data-cke-temp' );
16671667
}
16681668

1669-
function moveSelectionToDropPosition( editor, dropEvt ) {
1669+
function finalizeNativeDrop( editor, sourceWidget, range ) {
1670+
// Save the snapshot with the state before moving widget.
1671+
// Focus widget, so when we'll undo the DnD, widget will be focused.
1672+
sourceWidget.focus();
1673+
editor.fire( 'saveSnapshot' );
1674+
1675+
// Lock snapshot to group all steps of moving widget from the original place to the new one.
1676+
editor.fire( 'lockSnapshot', { dontUpdate: true } );
1677+
1678+
range.select();
1679+
1680+
var widgetHtml = sourceWidget.wrapper.getOuterHtml();
1681+
sourceWidget.wrapper.remove();
1682+
editor.widgets.destroy( sourceWidget, true );
1683+
editor.execCommand( 'paste', widgetHtml );
1684+
1685+
editor.fire( 'unlockSnapshot' );
1686+
}
1687+
1688+
function getRangeAtDropPosition( editor, dropEvt ) {
16701689
var $evt = dropEvt.data.$,
16711690
$range,
16721691
range = editor.createRange();
16731692

16741693
// Make testing possible.
1675-
if ( dropEvt.data.testRange ) {
1676-
dropEvt.data.testRange.select();
1677-
return;
1678-
}
1694+
if ( dropEvt.data.testRange )
1695+
return dropEvt.data.testRange;
16791696

16801697
// Webkits.
16811698
if ( document.caretRangeFromPoint ) {
@@ -1699,16 +1716,10 @@
16991716
range.moveToPosition( span, CKEDITOR.POSITION_BEFORE_START );
17001717
span.remove();
17011718
}
1719+
else
1720+
return null;
17021721

1703-
range.select();
1704-
}
1705-
1706-
function moveWidget( editor, sourceWidget ) {
1707-
var widgetHtml = sourceWidget.wrapper.getOuterHtml();
1708-
sourceWidget.wrapper.remove();
1709-
editor.widgets.destroy( sourceWidget, true );
1710-
editor.execCommand( 'paste', widgetHtml );
1711-
editor.fire( 'unlockSnapshot' );
1722+
return range;
17121723
}
17131724

17141725
function onEditableKey( widget, keyCode ) {
@@ -1911,7 +1922,8 @@
19111922
editable.attachListener( editable.isInline() ? editable : editor.document, 'drop', function( evt ) {
19121923
var dataStr = evt.data.$.dataTransfer.getData( 'text' ),
19131924
dataObj,
1914-
sourceWidget;
1925+
sourceWidget,
1926+
range;
19151927

19161928
if ( !dataStr )
19171929
return;
@@ -1932,23 +1944,19 @@
19321944
if ( dataObj.editor != editor.name || !( sourceWidget = widgetsRepo.instances[ dataObj.id ] ) )
19331945
return;
19341946

1935-
// Save the snapshot with the state before moving widget.
1936-
// Focus widget, so when we'll undo the DnD, widget will be focused.
1937-
sourceWidget.focus();
1938-
editor.fire( 'saveSnapshot' );
1939-
1940-
// Lock snapshot to group all steps of moving widget from the original place to the new one.
1941-
editor.fire( 'lockSnapshot', { dontUpdate: true } );
1942-
1943-
moveSelectionToDropPosition( editor, evt );
1947+
// Try to determine a DOM position at which drop happened. If none of methods
1948+
// which we support succeeded abort.
1949+
range = getRangeAtDropPosition( editor, evt );
1950+
if ( !range )
1951+
return;
19441952

1945-
// Hack to prevent cursor loss on Firefox. Without timeout widget is
1953+
// #11132 Hack to prevent cursor loss on Firefox. Without timeout widget is
19461954
// correctly pasted but then cursor is invisible (although it works) and can be restored
19471955
// only by blurring editable.
19481956
if ( CKEDITOR.env.gecko )
1949-
setTimeout( moveWidget, 0, editor, sourceWidget );
1957+
setTimeout( finalizeNativeDrop, 0, editor, sourceWidget, range );
19501958
else
1951-
moveWidget( editor, sourceWidget );
1959+
finalizeNativeDrop( editor, sourceWidget, range );
19521960
} );
19531961

19541962
// Register Lineutils's utilities as properties of repo.

0 commit comments

Comments
 (0)