Sfoglia il codice sorgente

Merge pull request #51 from ckeditor/t/32

Fix: An image dropped on another image will not redirect the browser to the file's path. Closes #32.
Szymon Kupś 8 anni fa
parent
commit
811bb221ca

+ 5 - 0
packages/ckeditor5-upload/src/imageuploadengine.js

@@ -64,6 +64,11 @@ export default class ImageUploadEngine extends Plugin {
 			}
 			}
 		} );
 		} );
 
 
+		// Prevents from browser redirecting to drag-end-dropped image.
+		editor.editing.view.on( 'dragover', ( evt, data ) => {
+			data.preventDefault();
+		} );
+
 		doc.on( 'change', ( evt, type, data ) => {
 		doc.on( 'change', ( evt, type, data ) => {
 			// Listen on document changes and:
 			// Listen on document changes and:
 			// * start upload process when image with `uploadId` attribute is inserted,
 			// * start upload process when image with `uploadId` attribute is inserted,

+ 10 - 0
packages/ckeditor5-upload/tests/imageuploadengine.js

@@ -359,4 +359,14 @@ describe( 'ImageUploadEngine', () => {
 
 
 		nativeReaderMock.mockSuccess( base64Sample );
 		nativeReaderMock.mockSuccess( base64Sample );
 	} );
 	} );
+
+	it( 'should prevent from browser redirecting when an image is dropped on another image', () => {
+		const spy = testUtils.sinon.spy();
+
+		editor.editing.view.fire( 'dragover', {
+			preventDefault: spy
+		} );
+
+		expect( spy.calledOnce ).to.equal( true );
+	} );
 } );
 } );

+ 3 - 0
packages/ckeditor5-upload/tests/manual/imageupload.md

@@ -5,6 +5,9 @@
 1. Press "Upload progress" button couple times to simulate upload process.
 1. Press "Upload progress" button couple times to simulate upload process.
 1. After uploading is complete your image should be replaced with sample image from server.
 1. After uploading is complete your image should be replaced with sample image from server.
 
 
+On the occasionn – when you drop an image on another image in the editor,
+your browser [**should not** redirect to the image](https://github.com/ckeditor/ckeditor5-upload/issues/32).
+
 Repeat all the steps with:
 Repeat all the steps with:
 * dropping multiple images,
 * dropping multiple images,
 * using toolbar button to add one and multiple images,
 * using toolbar button to add one and multiple images,