8
0
Просмотр исходного кода

Insert a link to a non-image file.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
e036d36ebb

+ 4 - 2
packages/ckeditor5-ckfinder/src/ckfindercommand.js

@@ -51,10 +51,12 @@ export default class CKFinderCommand extends Command {
 			finder.on( 'files:choose', evt => {
 				for ( const file of evt.data.files.toArray() ) {
 					// Use CKFinder file isImage() to insert only image-type files.
-					if ( file.isImage() ) {
-						const url = file.get( 'url' );
+					const url = file.get( 'url' );
 
+					if ( file.isImage() ) {
 						insertImage( editor.model, url ? url : finder.request( 'file:getProxyUrl', { file } ) );
+					} else {
+						editor.execute( 'link', url );
 					}
 				}
 			} );

+ 13 - 1
packages/ckeditor5-ckfinder/tests/ckfindercommand.js

@@ -11,6 +11,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
+import LinkEditing from '@ckeditor/ckeditor5-link/src/linkediting';
 import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
 import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
 
@@ -24,7 +25,7 @@ describe( 'CKFinderCommand', () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 			.create( {
-				plugins: [ Paragraph, ImageEditing, Notification ]
+				plugins: [ Paragraph, ImageEditing, LinkEditing, Notification ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -122,6 +123,17 @@ describe( 'CKFinderCommand', () => {
 				.to.equal( `[<image src="${ url }"></image>]<paragraph>foo</paragraph>` );
 		} );
 
+		it( 'should insert link if chosen file is not an image', () => {
+			const url = 'foo/bar.pdf';
+
+			command.execute();
+
+			mockFilesChooseEvent( [ mockFinderFile( url, false ) ] );
+
+			expect( getModelData( model ) )
+				.to.equal( `<paragraph>f[<$text linkHref="${ url }">o</$text>]o</paragraph>` );
+		} );
+
 		it( 'should pass CKFinder config options', () => {
 			const spy = sinon.spy( window.CKFinder, 'modal' );
 

+ 1 - 1
packages/ckeditor5-ckfinder/tests/ckfinderui.js

@@ -14,7 +14,7 @@ import ckfinderIcon from '@ckeditor/ckeditor5-ui/theme/icons/dropdown-arrow.svg'
 
 import CKFinder from '../src/ckfinder';
 
-describe( 'CKFinder', () => {
+describe( 'CKFinderUI', () => {
 	let editorElement, editor, button;
 
 	testUtils.createSinonSandbox();