Skip to content

Commit

Permalink
Merge pull request #14986 from ckeditor/ck/14710-dont-replace-the-ima…
Browse files Browse the repository at this point in the history
…ge-if-dropped-bellow

Fix (image): Image should not be replaced when dropped below a widget. Closes #14710. Closes #14740.
  • Loading branch information
arkflpc authored Sep 18, 2023
2 parents d37d4fe + 1e8a43d commit 03641ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ export default class ImageUploadEditing extends Plugin {
writer.setSelection( data.targetRanges.map( viewRange => editor.editing.mapper.toModelRange( viewRange ) ) );
}

// Upload images after the selection has changed in order to ensure the command's state is refreshed.
editor.model.enqueueChange( () => {
editor.execute( 'uploadImage', { file: images } );
} );
editor.execute( 'uploadImage', { file: images } );
} );
} );

Expand Down
14 changes: 9 additions & 5 deletions packages/ckeditor5-image/tests/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe( 'ImageUploadEditing', () => {

const id = fileRepository.getLoader( fileMock ).id;
expect( getModelData( model ) ).to.equal(
`<paragraph>foo[<imageInline uploadId="${ id }" uploadStatus="reading"></imageInline>]</paragraph>`
`<paragraph>foo</paragraph>[<imageBlock uploadId="${ id }" uploadStatus="reading"></imageBlock>]`
);
expect( eventInfo.stop.called ).to.be.true;
} );
Expand All @@ -198,7 +198,10 @@ describe( 'ImageUploadEditing', () => {
const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } );
setModelData( model, '<paragraph>[]foo</paragraph>' );

const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
const targetRange = model.createRange(
model.createPositionAt( doc.getRoot().getChild( 0 ), 3 ),
model.createPositionAt( doc.getRoot().getChild( 0 ), 3 )
);
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
Expand All @@ -214,7 +217,7 @@ describe( 'ImageUploadEditing', () => {
);
} );

it( 'should insert multiple image files when are pasted (block image type)', () => {
it( 'should insert multiple image files when are pasted', () => {
const files = [ createNativeFileMock(), createNativeFileMock() ];
const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } );
setModelData( model, '[]' );
Expand All @@ -228,12 +231,13 @@ describe( 'ImageUploadEditing', () => {
const id2 = fileRepository.getLoader( files[ 1 ] ).id;

expect( getModelData( model ) ).to.equal(
'<paragraph></paragraph>' +
`<imageBlock uploadId="${ id1 }" uploadStatus="reading"></imageBlock>` +
`[<imageBlock uploadId="${ id2 }" uploadStatus="reading"></imageBlock>]`
);
} );

it( 'should insert image when is pasted on allowed position when UploadImageCommand is disabled', () => {
it( 'should insert image when is pasted on allowed position when UploadImageCommand is enabled', () => {
setModelData( model, '<paragraph>foo</paragraph>[<imageBlock></imageBlock>]' );

const fileMock = createNativeFileMock();
Expand All @@ -250,7 +254,7 @@ describe( 'ImageUploadEditing', () => {

const id = fileRepository.getLoader( fileMock ).id;
expect( getModelData( model ) ).to.equal(
`<paragraph>[<imageInline uploadId="${ id }" uploadStatus="reading"></imageInline>]foo</paragraph><imageBlock></imageBlock>`
`[<imageBlock uploadId="${ id }" uploadStatus="reading"></imageBlock>]<paragraph>foo</paragraph><imageBlock></imageBlock>`
);
} );

Expand Down

0 comments on commit 03641ca

Please sign in to comment.