瀏覽代碼

Switched LinkForm to the read-only mode when link and unlink commands are disabled.

Oskar Wróbel 8 年之前
父節點
當前提交
92a1662823
共有 2 個文件被更改,包括 30 次插入1 次删除
  1. 8 1
      packages/ckeditor5-link/src/link.js
  2. 22 0
      packages/ckeditor5-link/tests/link.js

+ 8 - 1
packages/ckeditor5-link/src/link.js

@@ -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' );
+		// Switch form to the read-only mode when commands are disabled.
+		formView.urlInputView.inputView.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', () => {

+ 22 - 0
packages/ckeditor5-link/tests/link.js

@@ -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.inputView.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.inputView.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>' );