|
1666 | 1666 | return element.hasAttribute( 'data-cke-temp' );
|
1667 | 1667 | }
|
1668 | 1668 |
|
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 ) { |
1670 | 1689 | var $evt = dropEvt.data.$,
|
1671 | 1690 | $range,
|
1672 | 1691 | range = editor.createRange();
|
1673 | 1692 |
|
1674 | 1693 | // 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; |
1679 | 1696 |
|
1680 | 1697 | // Webkits.
|
1681 | 1698 | if ( document.caretRangeFromPoint ) {
|
|
1699 | 1716 | range.moveToPosition( span, CKEDITOR.POSITION_BEFORE_START );
|
1700 | 1717 | span.remove();
|
1701 | 1718 | }
|
| 1719 | + else |
| 1720 | + return null; |
1702 | 1721 |
|
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; |
1712 | 1723 | }
|
1713 | 1724 |
|
1714 | 1725 | function onEditableKey( widget, keyCode ) {
|
|
1911 | 1922 | editable.attachListener( editable.isInline() ? editable : editor.document, 'drop', function( evt ) {
|
1912 | 1923 | var dataStr = evt.data.$.dataTransfer.getData( 'text' ),
|
1913 | 1924 | dataObj,
|
1914 |
| - sourceWidget; |
| 1925 | + sourceWidget, |
| 1926 | + range; |
1915 | 1927 |
|
1916 | 1928 | if ( !dataStr )
|
1917 | 1929 | return;
|
|
1932 | 1944 | if ( dataObj.editor != editor.name || !( sourceWidget = widgetsRepo.instances[ dataObj.id ] ) )
|
1933 | 1945 | return;
|
1934 | 1946 |
|
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; |
1944 | 1952 |
|
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 |
1946 | 1954 | // correctly pasted but then cursor is invisible (although it works) and can be restored
|
1947 | 1955 | // only by blurring editable.
|
1948 | 1956 | if ( CKEDITOR.env.gecko )
|
1949 |
| - setTimeout( moveWidget, 0, editor, sourceWidget ); |
| 1957 | + setTimeout( finalizeNativeDrop, 0, editor, sourceWidget, range ); |
1950 | 1958 | else
|
1951 |
| - moveWidget( editor, sourceWidget ); |
| 1959 | + finalizeNativeDrop( editor, sourceWidget, range ); |
1952 | 1960 | } );
|
1953 | 1961 |
|
1954 | 1962 | // Register Lineutils's utilities as properties of repo.
|
|
0 commit comments