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

Commit

Permalink
Removed Unlink UI component from the ComponentFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Aug 22, 2017
1 parent 1c6a6fe commit aad5cc6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 59 deletions.
32 changes: 0 additions & 32 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import LinkFormView from './ui/linkformview';

import linkIcon from '../theme/icons/link.svg';
import unlinkIcon from '../theme/icons/unlink.svg';

import '../theme/theme.scss';

const linkKeystroke = 'Ctrl+K';
Expand Down Expand Up @@ -74,7 +72,6 @@ export default class Link extends Plugin {

// Create toolbar buttons.
this._createToolbarLinkButton();
this._createToolbarUnlinkButton();

// Attach lifecycle actions to the the balloon.
this._attachActions();
Expand Down Expand Up @@ -160,35 +157,6 @@ export default class Link extends Plugin {
} );
}

/**
* Creates a toolbar Unlink button. Clicking this button will unlink
* the selected link.
*
* @private
*/
_createToolbarUnlinkButton() {
const editor = this.editor;
const t = editor.t;
const unlinkCommand = editor.commands.get( 'unlink' );

editor.ui.componentFactory.add( 'unlink', locale => {
const button = new ButtonView( locale );

button.isEnabled = false;
button.label = t( 'Unlink' );
button.icon = unlinkIcon;
button.tooltip = true;

// Bind button to the command.
button.bind( 'isEnabled' ).to( unlinkCommand, 'isEnabled' );

// Execute unlink command and hide panel, if open on button click.
this.listenTo( button, 'execute', () => editor.execute( 'unlink' ) );

return button;
} );
}

/**
* Attaches actions that control whether the balloon panel containing the
* {@link #formView} is visible or not.
Expand Down
28 changes: 1 addition & 27 deletions tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobs
testUtils.createSinonSandbox();

describe( 'Link', () => {
let editor, linkFeature, linkButton, unlinkButton, balloon, formView, editorElement;
let editor, linkFeature, linkButton, balloon, formView, editorElement;

beforeEach( () => {
editorElement = document.createElement( 'div' );
Expand All @@ -39,7 +39,6 @@ describe( 'Link', () => {

linkFeature = editor.plugins.get( Link );
linkButton = editor.ui.componentFactory.create( 'link' );
unlinkButton = editor.ui.componentFactory.create( 'unlink' );
balloon = editor.plugins.get( ContextualBalloon );
formView = linkFeature.formView;

Expand Down Expand Up @@ -437,31 +436,6 @@ describe( 'Link', () => {
} );
} );

describe( 'unlink toolbar button', () => {
it( 'should register unlink button', () => {
expect( unlinkButton ).to.instanceOf( ButtonView );
} );

it( 'should bind unlinkButtonView to unlink command', () => {
const command = editor.commands.get( 'unlink' );

command.isEnabled = true;
expect( unlinkButton.isEnabled ).to.be.true;

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

it( 'should execute unlink command on unlinkButtonView execute event', () => {
const executeSpy = testUtils.sinon.spy( editor, 'execute' );

unlinkButton.fire( 'execute' );

expect( executeSpy.calledOnce ).to.true;
expect( executeSpy.calledWithExactly( 'unlink' ) ).to.true;
} );
} );

describe( 'keyboard support', () => {
it( 'should show the #_balloon with selected #formView on Ctrl+K keystroke', () => {
const spy = testUtils.sinon.stub( linkFeature, '_showPanel' ).returns( {} );
Expand Down

0 comments on commit aad5cc6

Please sign in to comment.