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 #120 from ckeditor/t/78
Browse files Browse the repository at this point in the history
Fix: The URL field's value should be updated each time the form shows up. Closes #78.
  • Loading branch information
szymonkups committed May 15, 2017
2 parents 6d18c55 + af224ba commit 3b702aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,23 @@ export default class Link extends Plugin {
* @return {Promise} A promise resolved when the {@link #formView} {@link module:ui/view~View#init} is done.
*/
_showPanel( focusInput ) {
const editing = this.editor.editing;
const editor = this.editor;
const command = editor.commands.get( 'link' );
const editing = editor.editing;
const showViewDocument = editing.view;
const showIsCollapsed = showViewDocument.selection.isCollapsed;
const showSelectedLink = this._getSelectedLinkElement();

// https://github.com/ckeditor/ckeditor5-link/issues/53
this.formView.unlinkButtonView.isVisible = !!showSelectedLink;

// Make sure that each time the panel shows up, the URL field remains in sync with the value of
// the command. If the user typed in the input, then canceled the balloon (`urlInputView#value` stays
// 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;

this.listenTo( showViewDocument, 'render', () => {
const renderSelectedLink = this._getSelectedLinkElement();
const renderIsCollapsed = showViewDocument.selection.isCollapsed;
Expand Down
13 changes: 13 additions & 0 deletions tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ 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', () => {
setModelData( editor.document, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );

// Mock some leftover value **in DOM**, e.g. after previous editing.
formView.urlInputView.inputView.element.value = 'leftover';

return linkFeature._showPanel()
.then( () => {
expect( formView.urlInputView.inputView.element.value ).to.equal( 'url' );
} );
} );

describe( 'when the document is rendering', () => {
it( 'should not duplicate #render listeners', () => {
const viewDocument = editor.editing.view;
Expand Down

0 comments on commit 3b702aa

Please sign in to comment.