浏览代码

Fix: URL input value should not be 'undefined' when no link is selected. Closes #123.

Aleksander Nowodzinski 8 年之前
父节点
当前提交
f8dcaaec90
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 2 1
      packages/ckeditor5-link/src/link.js
  2. 11 1
      packages/ckeditor5-link/tests/link.js

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

@@ -243,7 +243,8 @@ export default class Link extends Plugin {
 		// unaltered) and re-opened it without changing the value of the link command (e.g. because they
 		// clicked the same link), they would see the old value instead of the actual value of the command.
 		// https://github.com/ckeditor/ckeditor5-link/issues/78
-		this.formView.urlInputView.inputView.element.value = command.value;
+		// https://github.com/ckeditor/ckeditor5-link/issues/123
+		this.formView.urlInputView.inputView.element.value = command.value || '';
 
 		this.listenTo( showViewDocument, 'render', () => {
 			const renderSelectedLink = this._getSelectedLinkElement();

+ 11 - 1
packages/ckeditor5-link/tests/link.js

@@ -216,7 +216,7 @@ describe( 'Link', () => {
 		} );
 
 		// https://github.com/ckeditor/ckeditor5-link/issues/78
-		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command', () => {
+		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (selected link)', () => {
 			setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 			// Mock some leftover value **in DOM**, e.g. after previous editing.
@@ -228,6 +228,16 @@ describe( 'Link', () => {
 				} );
 		} );
 
+		// https://github.com/ckeditor/ckeditor5-link/issues/123
+		it( 'should make sure the URL input in the #formView always stays in sync with the value of the command (no link selected)', () => {
+			setModelData( editor.document, '<paragraph>f[]oo</paragraph>' );
+
+			return linkFeature._showPanel()
+				.then( () => {
+					expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
+				} );
+		} );
+
 		describe( 'when the document is rendering', () => {
 			it( 'should not duplicate #render listeners', () => {
 				const viewDocument = editor.editing.view;