Skip to content

Commit

Permalink
Merge pull request #17433 from ckeditor/ck/16101
Browse files Browse the repository at this point in the history
Fix (clipboard): An in-text drop of an inline object with elements inside should be possible. Closes #16101.
  • Loading branch information
arkflpc authored Nov 8, 2024
2 parents 7f0da84 + bd96d0c commit e1093eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ckeditor5-clipboard/src/dragdroptarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function findDropTargetRange(
const targetViewPosition = targetViewRanges[ 0 ].start;
const targetModelPosition = mapper.toModelPosition( targetViewPosition );
const canDropOnPosition = !draggedRange || Array
.from( draggedRange.getItems() )
.from( draggedRange.getItems( { shallow: true } ) )
.every( item => model.schema.checkChild( targetModelPosition, item as Node ) );

if ( canDropOnPosition ) {
Expand Down
41 changes: 41 additions & 0 deletions packages/ckeditor5-clipboard/tests/dragdroptarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils.js';
import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js';

import { CustomTitle } from './utils/customtitleplugin.js';
import { toWidget, toWidgetEditable } from '@ckeditor/ckeditor5-widget';

describe( 'Drag and Drop target', () => {
let editorElement, editor, model, view, viewDocument, root, mapper, domConverter, dragDropTarget;
Expand Down Expand Up @@ -510,6 +511,46 @@ describe( 'Drag and Drop target', () => {
) ).to.be.true;
} );

it( 'should put drop target marker inside a text node (even if dragged range is an inline object with block content)', () => {
model.schema.register( 'inlineWidget', { inheritAllFrom: '$inlineObject' } );
model.schema.register( 'widgetTitle', { isLimit: true, allowIn: 'inlineWidget', allowContentOf: '$block' } );

editor.conversion.for( 'editingDowncast' )
.elementToElement( {
model: 'inlineWidget',
view: ( modelElement, { writer: viewWriter } ) => {
return toWidget( viewWriter.createContainerElement( 'span' ), viewWriter );
}
} )
.elementToElement( {
model: 'widgetTitle',
view: ( modelElement, { writer: viewWriter } ) => {
return toWidgetEditable( viewWriter.createEditableElement( 'h1' ), viewWriter );
}
} );

setModelData( model, '<paragraph>[<inlineWidget><widgetTitle>abc</widgetTitle></inlineWidget>]foobar</paragraph>' );

const modelPosition = model.createPositionAt( root.getChild( 0 ), 4 );
const viewPosition = mapper.toViewPosition( modelPosition );
const domNode = domConverter.findCorrespondingDomText( viewPosition.parent ).parentNode;

const { clientX, clientY } = getMockedMousePosition( { domNode } );

dragDropTarget.updateDropMarker(
mapper.findMappedViewAncestor( viewPosition ),
[ view.createRange( viewPosition ) ],
clientX,
clientY,
false,
LiveRange.fromRange( model.document.selection.getFirstRange() )
);

expect( model.markers.get( 'drop-target' ).getRange().start.isEqual(
model.createPositionAt( root.getChild( 0 ), 4 )
) ).to.be.true;
} );

it( 'should not remove drop target marker if dragging left some nested element', () => {
setModelData( model, '<paragraph>[foo]bar</paragraph>' );

Expand Down

0 comments on commit e1093eb

Please sign in to comment.