Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from ckeditor/t/48
Browse files Browse the repository at this point in the history
Fix: CKFinderCommand should work when either `'link'` or `'imageInsert'` command is enabled. Closes #48.
  • Loading branch information
Reinmar authored Sep 13, 2019
2 parents d7ec890 + 39602c2 commit d82a762
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"dependencies": {
"@ckeditor/ckeditor5-adapter-ckfinder": "^11.0.5",
"@ckeditor/ckeditor5-core": "^12.3.0",
"@ckeditor/ckeditor5-image": "^14.0.0",
"@ckeditor/ckeditor5-link": "^11.1.2",
"@ckeditor/ckeditor5-ui": "^14.0.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-editor-classic": "^12.1.4",
"@ckeditor/ckeditor5-clipboard": "^12.0.2",
"@ckeditor/ckeditor5-engine": "^14.0.0",
"@ckeditor/ckeditor5-image": "^14.0.0",
"@ckeditor/ckeditor5-link": "^11.1.2",
"@ckeditor/ckeditor5-paragraph": "^11.0.5",
"@ckeditor/ckeditor5-utils": "^14.0.0",
"eslint": "^5.5.0",
Expand Down
14 changes: 10 additions & 4 deletions src/ckfindercommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* The CKFinder command. It is used by the {@link module:ckfinder/ckfinderediting~CKFinderEditing ckfinder editng feature}
* The CKFinder command. It is used by the {@link module:ckfinder/ckfinderediting~CKFinderEditing ckfinder editing feature}
* to open a CKFinder file browser to insert an image or a link to a file into content.
*
* editor.execute( 'ckfinder' );
*
* **Note:** This command uses other features to perform tasks:
* - To insert images the {@link module:image/image/imageinsertcommand~ImageInsertCommand 'imageInsert'} command
* from the {@link module:image/image~Image Image feature}.
* - To insert links to files the {@link module:link/linkcommand~LinkCommand 'link'} command
* from the {@link module:link/link~Link Link feature}.
*
* @extends module:core/command~Command
*/
export default class CKFinderCommand extends Command {
Expand All @@ -38,11 +44,11 @@ export default class CKFinderCommand extends Command {
* @inheritDoc
*/
refresh() {
const imageCommand = this.editor.commands.get( 'imageUpload' );
const imageCommand = this.editor.commands.get( 'imageInsert' );
const linkCommand = this.editor.commands.get( 'link' );

// The CKFinder command is enabled when one of image or link command is enabled.
this.isEnabled = imageCommand && linkCommand && ( imageCommand.isEnabled || linkCommand.isEnabled );
this.isEnabled = imageCommand.isEnabled || linkCommand.isEnabled;
}

/**
Expand Down Expand Up @@ -124,7 +130,7 @@ export default class CKFinderCommand extends Command {
}

function insertImages( editor, urls ) {
const imageCommand = editor.commands.get( 'imageUpload' );
const imageCommand = editor.commands.get( 'imageInsert' );

// Check if inserting an image is actually possible - it might be possible to only insert a link.
if ( !imageCommand.isEnabled ) {
Expand Down
4 changes: 3 additions & 1 deletion src/ckfinderediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Image from '@ckeditor/ckeditor5-image/src/image';
import Link from '@ckeditor/ckeditor5-link/src/link';
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';

import CKFinderCommand from './ckfindercommand';
Expand All @@ -29,7 +31,7 @@ export default class CKFinderEditing extends Plugin {
* @inheritDoc
*/
static get requires() {
return [ Notification ];
return [ Notification, Image, Link ];
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/ckfindercommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ describe( 'CKFinderCommand', () => {

expect( command.isEnabled ).to.be.false;
} );

it( 'should be true when imageInsert or link command is enabled', () => {
setModelData( model, '<paragraph>[]</paragraph>' );
const insertImage = editor.commands.get( 'imageInsert' );
const linkCommand = editor.commands.get( 'link' );

insertImage.isEnabled = false;
linkCommand.isEnabled = false;

command.refresh();
expect( command.isEnabled ).to.be.false;

linkCommand.isEnabled = false;
insertImage.isEnabled = true;

command.refresh();
expect( command.isEnabled ).to.be.true;

linkCommand.isEnabled = true;
insertImage.isEnabled = false;

command.refresh();
expect( command.isEnabled ).to.be.true;
} );
} );

describe( 'execute()', () => {
Expand Down
10 changes: 10 additions & 0 deletions tests/ckfinderediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import Command from '@ckeditor/ckeditor5-core/src/command';
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import Image from '@ckeditor/ckeditor5-image/src/image';
import Link from '@ckeditor/ckeditor5-link/src/link';
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
import global from '@ckeditor/ckeditor5-utils/src/dom/global';

Expand Down Expand Up @@ -45,6 +47,14 @@ describe( 'CKFinderEditing', () => {
expect( editor.plugins.get( Notification ) ).to.instanceOf( Notification );
} );

it( 'should load Image plugin', () => {
expect( editor.plugins.get( Image ) ).to.instanceOf( Image );
} );

it( 'should load Link plugin', () => {
expect( editor.plugins.get( Link ) ).to.instanceOf( Link );
} );

it( 'should register command', () => {
const command = editor.commands.get( 'ckfinder' );

Expand Down

0 comments on commit d82a762

Please sign in to comment.