From a83f698e8659b22637ae53daba98ffd72c89a50d Mon Sep 17 00:00:00 2001 From: Illia Sheremetov Date: Wed, 13 Sep 2023 14:39:55 +0200 Subject: [PATCH 1/2] Fix image pasting --- .../src/imageupload/imageuploadediting.ts | 5 +--- .../tests/imageupload/imageuploadediting.js | 30 ++++--------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/packages/ckeditor5-image/src/imageupload/imageuploadediting.ts b/packages/ckeditor5-image/src/imageupload/imageuploadediting.ts index cd62c7df1c8..aadc7ec368c 100644 --- a/packages/ckeditor5-image/src/imageupload/imageuploadediting.ts +++ b/packages/ckeditor5-image/src/imageupload/imageuploadediting.ts @@ -125,10 +125,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 } ); } ); } ); diff --git a/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js b/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js index e05ceb20a0a..1fef7580ecf 100644 --- a/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js +++ b/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js @@ -171,7 +171,7 @@ describe( 'ImageUploadEditing', () => { const id = fileRepository.getLoader( fileMock ).id; expect( getModelData( model ) ).to.equal( - `foo[]` + `foo[]` ); expect( eventInfo.stop.called ).to.be.true; } ); @@ -193,28 +193,7 @@ describe( 'ImageUploadEditing', () => { ); } ); - it( 'should insert multiple image files when are pasted (inline image type)', () => { - const files = [ createNativeFileMock(), createNativeFileMock() ]; - const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } ); - setModelData( model, '[]foo' ); - - const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) ); - const targetViewRange = editor.editing.mapper.toViewRange( targetRange ); - - viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } ); - - const id1 = fileRepository.getLoader( files[ 0 ] ).id; - const id2 = fileRepository.getLoader( files[ 1 ] ).id; - - expect( getModelData( model ) ).to.equal( - '' + - `foo` + - `[]` + - '' - ); - } ); - - 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, '[]' ); @@ -228,12 +207,13 @@ describe( 'ImageUploadEditing', () => { const id2 = fileRepository.getLoader( files[ 1 ] ).id; expect( getModelData( model ) ).to.equal( + '' + `` + `[]` ); } ); - 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, 'foo[]' ); const fileMock = createNativeFileMock(); @@ -250,7 +230,7 @@ describe( 'ImageUploadEditing', () => { const id = fileRepository.getLoader( fileMock ).id; expect( getModelData( model ) ).to.equal( - `[]foo` + `[]foo` ); } ); From 1e8a43dc26e1b0ba6790a6a33e07140e974e60c6 Mon Sep 17 00:00:00 2001 From: Illia Sheremetov Date: Thu, 14 Sep 2023 14:04:20 +0200 Subject: [PATCH 2/2] Revert test --- .../tests/imageupload/imageuploadediting.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js b/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js index 1fef7580ecf..78e1ae14962 100644 --- a/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js +++ b/packages/ckeditor5-image/tests/imageupload/imageuploadediting.js @@ -193,6 +193,30 @@ describe( 'ImageUploadEditing', () => { ); } ); + it( 'should insert multiple image files when are pasted (inline image type)', () => { + const files = [ createNativeFileMock(), createNativeFileMock() ]; + const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } ); + setModelData( model, '[]foo' ); + + 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 ] } ); + + const id1 = fileRepository.getLoader( files[ 0 ] ).id; + const id2 = fileRepository.getLoader( files[ 1 ] ).id; + + expect( getModelData( model ) ).to.equal( + '' + + `foo` + + `[]` + + '' + ); + } ); + it( 'should insert multiple image files when are pasted', () => { const files = [ createNativeFileMock(), createNativeFileMock() ]; const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } );