From 38b0b1bf2fbfc1ccbef61020040c86ee8ce8b07a Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Fri, 19 May 2017 16:54:35 +0200 Subject: [PATCH] Fix: URL input value should not be 'undefined' when no link is selected. Closes #123. --- src/link.js | 3 ++- tests/link.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/link.js b/src/link.js index 6b43b98..1bdedc5 100644 --- a/src/link.js +++ b/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(); diff --git a/tests/link.js b/tests/link.js index f585167..dc2117b 100644 --- a/tests/link.js +++ b/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, '<$text linkHref="url">f[]oo' ); // 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, 'f[]oo' ); + + 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;