Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 0069dc7

Browse files
authored
Merge pull request #226 from ckeditor/t/171
Fix: Link balloon will not be shown if no link was added after command execution. Closes #171.
2 parents e3c8676 + 466be57 commit 0069dc7

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/linkui.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,17 @@ export default class LinkUI extends Plugin {
154154
// Execute link command after clicking the "Save" button.
155155
this.listenTo( formView, 'submit', () => {
156156
editor.execute( 'link', formView.urlInputView.inputView.element.value );
157-
this._removeFormView();
157+
this._closeFormView();
158158
} );
159159

160160
// Hide the panel after clicking the "Cancel" button.
161161
this.listenTo( formView, 'cancel', () => {
162-
this._removeFormView();
162+
this._closeFormView();
163163
} );
164164

165165
// Close the panel on esc key press when the **form has focus**.
166166
formView.keystrokes.set( 'Esc', ( data, cancel ) => {
167-
this._removeFormView();
167+
this._closeFormView();
168168
cancel();
169169
} );
170170

@@ -309,6 +309,22 @@ export default class LinkUI extends Plugin {
309309
this.formView.urlInputView.inputView.element.value = linkCommand.value || '';
310310
}
311311

312+
/**
313+
* Closes form view. Decides whether the balloon should be hidden completely or if action view should be shown. This is decided upon
314+
* link command value (which has value if the document selection is in link).
315+
*
316+
* @private
317+
*/
318+
_closeFormView() {
319+
const linkCommand = this.editor.commands.get( 'link' );
320+
321+
if ( linkCommand.value !== undefined ) {
322+
this._removeFormView();
323+
} else {
324+
this._hideUI();
325+
}
326+
}
327+
312328
/**
313329
* Removes the {@link #formView} from the {@link #_balloon}.
314330
*

tests/linkui.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,15 +845,26 @@ describe( 'LinkUI', () => {
845845
expect( focusEditableSpy.calledOnce ).to.be.true;
846846
} );
847847

848-
it( 'should hide and reveal the #actionsView on formView#cancel event', () => {
848+
it( 'should hide and reveal the #actionsView on formView#cancel event if link command has a value', () => {
849849
linkUIFeature._showUI();
850+
851+
const command = editor.commands.get( 'link' );
852+
command.value = 'http://foo.com';
853+
850854
formView.fire( 'cancel' );
851855

852856
expect( balloon.visibleView ).to.equal( actionsView );
853857
expect( focusEditableSpy.calledOnce ).to.be.true;
854858
} );
855859

856-
it( 'should hide after Esc key press', () => {
860+
it( 'should hide the balloon on formView#cancel if link command does not have a value', () => {
861+
linkUIFeature._showUI();
862+
formView.fire( 'cancel' );
863+
864+
expect( balloon.visibleView ).to.be.null;
865+
} );
866+
867+
it( 'should hide and reveal the #actionsView after Esc key press if link command has a value', () => {
857868
const keyEvtData = {
858869
keyCode: keyCodes.esc,
859870
preventDefault: sinon.spy(),
@@ -862,11 +873,29 @@ describe( 'LinkUI', () => {
862873

863874
linkUIFeature._showUI();
864875

876+
const command = editor.commands.get( 'link' );
877+
command.value = 'http://foo.com';
878+
865879
formView.keystrokes.press( keyEvtData );
880+
866881
expect( balloon.visibleView ).to.equal( actionsView );
867882
expect( focusEditableSpy.calledOnce ).to.be.true;
868883
} );
869884

885+
it( 'should hide the balloon after Esc key press if link command does not have a value', () => {
886+
const keyEvtData = {
887+
keyCode: keyCodes.esc,
888+
preventDefault: sinon.spy(),
889+
stopPropagation: sinon.spy()
890+
};
891+
892+
linkUIFeature._showUI();
893+
894+
formView.keystrokes.press( keyEvtData );
895+
896+
expect( balloon.visibleView ).to.be.null;
897+
} );
898+
870899
// https://github.com/ckeditor/ckeditor5/issues/1501
871900
it( 'should blur url input element before hiding the view', () => {
872901
linkUIFeature._showUI();

0 commit comments

Comments
 (0)