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 #136 from ckeditor/t/135
Browse files Browse the repository at this point in the history
Feature: `LinkFormView` controls should enter the read-only mode when `LinkCommand` and `UnlinkCommand` are disabled. Closes #135.
  • Loading branch information
oleq authored Jul 13, 2017
2 parents e38acff + bb1954b commit 50da835
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ export default class Link extends Plugin {
_createForm() {
const editor = this.editor;
const formView = new LinkFormView( editor.locale );
const linkCommand = editor.commands.get( 'link' );
const unlinkCommand = editor.commands.get( 'unlink' );

formView.urlInputView.bind( 'value' ).to( linkCommand, 'value' );

formView.urlInputView.bind( 'value' ).to( editor.commands.get( 'link' ), 'value' );
// Form elements should be read-only when corresponding commands are disabled.
formView.urlInputView.bind( 'isReadOnly' ).to( linkCommand, 'isEnabled', value => !value );
formView.saveButtonView.bind( 'isEnabled' ).to( linkCommand );
formView.unlinkButtonView.bind( 'isEnabled' ).to( unlinkCommand );

// Execute link command after clicking on formView `Save` button.
this.listenTo( formView, 'submit', () => {
Expand Down
22 changes: 22 additions & 0 deletions tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,28 @@ describe( 'Link', () => {
sinon.assert.calledOnce( spy );
} );

it( 'should disable #formView elements when link and unlink commands are disabled', () => {
setModelData( editor.document, '<paragraph>f[o]o</paragraph>' );

linkFeature._showPanel();

editor.commands.get( 'link' ).isEnabled = true;
editor.commands.get( 'unlink' ).isEnabled = true;

expect( formView.urlInputView.isReadOnly ).to.false;
expect( formView.saveButtonView.isEnabled ).to.true;
expect( formView.unlinkButtonView.isEnabled ).to.true;
expect( formView.cancelButtonView.isEnabled ).to.true;

editor.commands.get( 'link' ).isEnabled = false;
editor.commands.get( 'unlink' ).isEnabled = false;

expect( formView.urlInputView.isReadOnly ).to.true;
expect( formView.saveButtonView.isEnabled ).to.false;
expect( formView.unlinkButtonView.isEnabled ).to.false;
expect( formView.cancelButtonView.isEnabled ).to.true;
} );

// https://github.com/ckeditor/ckeditor5-link/issues/53
it( 'should set formView.unlinkButtonView#isVisible depending on the selection in a link or not', () => {
setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
Expand Down

0 comments on commit 50da835

Please sign in to comment.