From a3666bc78a374c6c5a00dd47c768f643b7c4b061 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 20 Jul 2017 15:57:34 +0200 Subject: [PATCH] Fix: Unlink button in the balloon should be visible when a link is partially selected. Closes #141. --- src/link.js | 7 ++++--- tests/link.js | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/link.js b/src/link.js index 63ea05f..3c5f730 100644 --- a/src/link.js +++ b/src/link.js @@ -241,14 +241,15 @@ export default class Link extends Plugin { */ _showPanel( focusInput ) { const editor = this.editor; - const command = editor.commands.get( 'link' ); + const linkCommand = editor.commands.get( 'link' ); + const unlinkCommand = editor.commands.get( 'unlink' ); 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; + this.formView.unlinkButtonView.isVisible = unlinkCommand.isEnabled; // 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 @@ -256,7 +257,7 @@ export default class Link extends Plugin { // 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 // https://github.com/ckeditor/ckeditor5-link/issues/123 - this.formView.urlInputView.inputView.element.value = command.value || ''; + this.formView.urlInputView.inputView.element.value = linkCommand.value || ''; this.listenTo( showViewDocument, 'render', () => { const renderSelectedLink = this._getSelectedLinkElement(); diff --git a/tests/link.js b/tests/link.js index 999e970..9f8fe5a 100644 --- a/tests/link.js +++ b/tests/link.js @@ -208,6 +208,11 @@ describe( 'Link', () => { linkFeature._showPanel(); expect( formView.unlinkButtonView.isVisible ).to.be.true; + + setModelData( editor.document, '<$text linkHref="url">[fo]o' ); + + linkFeature._showPanel(); + expect( formView.unlinkButtonView.isVisible ).to.be.true; } ); // https://github.com/ckeditor/ckeditor5-link/issues/78