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

Commit d6c45df

Browse files
authored
Merge pull request #243 from ckeditor/t/242
Fix: Improved balloon positioning when there is more than one stack in the rotator.
2 parents 4932ced + 0bd22c0 commit d6c45df

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"lodash-es": "^4.17.10"
1717
},
1818
"devDependencies": {
19+
"@ckeditor/ckeditor5-block-quote": "^11.1.2",
1920
"@ckeditor/ckeditor5-clipboard": "^12.0.1",
2021
"@ckeditor/ckeditor5-editor-classic": "^12.1.3",
2122
"@ckeditor/ckeditor5-enter": "^11.0.4",

src/linkui.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ export default class LinkUI extends Plugin {
414414
const editor = this.editor;
415415

416416
this.stopListening( editor.ui, 'update' );
417+
this.stopListening( this._balloon, 'change:visibleView' );
417418

418419
// Make sure the focus always gets back to the editable _before_ removing the focused form view.
419420
// Doing otherwise causes issues in some browsers. See https://github.com/ckeditor/ckeditor5-link/issues/193.
@@ -441,7 +442,7 @@ export default class LinkUI extends Plugin {
441442
let prevSelectedLink = this._getSelectedLinkElement();
442443
let prevSelectionParent = getSelectionParent();
443444

444-
this.listenTo( editor.ui, 'update', () => {
445+
const update = () => {
445446
const selectedLink = this._getSelectedLinkElement();
446447
const selectionParent = getSelectionParent();
447448

@@ -460,9 +461,10 @@ export default class LinkUI extends Plugin {
460461
this._hideUI();
461462
}
462463
// Update the position of the panel when:
464+
// * link panel is in the visible stack
463465
// * the selection remains in the original link element,
464466
// * there was no link element in the first place, i.e. creating a new link
465-
else {
467+
else if ( this._isUIVisible ) {
466468
// If still in a link element, simply update the position of the balloon.
467469
// If there was no link (e.g. inserting one), the balloon must be moved
468470
// to the new position in the editing view (a new native DOM range).
@@ -471,13 +473,16 @@ export default class LinkUI extends Plugin {
471473

472474
prevSelectedLink = selectedLink;
473475
prevSelectionParent = selectionParent;
474-
} );
476+
};
475477

476478
function getSelectionParent() {
477479
return viewDocument.selection.focus.getAncestors()
478480
.reverse()
479481
.find( node => node.is( 'element' ) );
480482
}
483+
484+
this.listenTo( editor.ui, 'update', update );
485+
this.listenTo( this._balloon, 'change:visibleView', update );
481486
}
482487

483488
/**

tests/linkui.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
1212
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
1313

1414
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
15+
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
1516
import LinkEditing from '../src/linkediting';
1617
import LinkUI from '../src/linkui';
1718
import LinkFormView from '../src/ui/linkformview';
@@ -33,7 +34,7 @@ describe( 'LinkUI', () => {
3334

3435
return ClassicTestEditor
3536
.create( editorElement, {
36-
plugins: [ LinkEditing, LinkUI, Paragraph ]
37+
plugins: [ LinkEditing, LinkUI, Paragraph, BlockQuote ]
3738
} )
3839
.then( newEditor => {
3940
editor = newEditor;
@@ -269,6 +270,42 @@ describe( 'LinkUI', () => {
269270
expect( balloon.visibleView ).to.equal( formView );
270271
} );
271272

273+
// https://github.com/ckeditor/ckeditor5-link/issues/242.
274+
it( 'should update balloon position when is switched in rotator to a visible panel', () => {
275+
setModelData( editor.model, '<paragraph>fo<$text linkHref="foo">o[] b</$text>ar</paragraph>' );
276+
linkUIFeature._showUI();
277+
278+
const customView = new View();
279+
const linkViewElement = editor.editing.view.document.getRoot().getChild( 0 ).getChild( 1 );
280+
const linkDomElement = editor.editing.view.domConverter.mapViewToDom( linkViewElement );
281+
282+
expect( balloon.visibleView ).to.equal( actionsView );
283+
expect( balloon.view.pin.lastCall.args[ 0 ].target ).to.equal( linkDomElement );
284+
285+
balloon.add( {
286+
stackId: 'custom',
287+
view: customView,
288+
position: { target: {} }
289+
} );
290+
291+
balloon.showStack( 'custom' );
292+
293+
expect( balloon.visibleView ).to.equal( customView );
294+
expect( balloon.hasView( actionsView ) ).to.equal( true );
295+
296+
editor.execute( 'blockQuote' );
297+
balloon.showStack( 'main' );
298+
299+
expect( balloon.visibleView ).to.equal( actionsView );
300+
expect( balloon.hasView( customView ) ).to.equal( true );
301+
expect( balloon.view.pin.lastCall.args[ 0 ].target ).to.not.equal( linkDomElement );
302+
303+
const newLinkViewElement = editor.editing.view.document.getRoot().getChild( 0 ).getChild( 0 ).getChild( 1 );
304+
const newLinkDomElement = editor.editing.view.domConverter.mapViewToDom( newLinkViewElement );
305+
306+
expect( balloon.view.pin.lastCall.args[ 0 ].target ).to.equal( newLinkDomElement );
307+
} );
308+
272309
describe( 'response to ui#update', () => {
273310
let view, viewDocument;
274311

@@ -337,6 +374,31 @@ describe( 'LinkUI', () => {
337374
} );
338375
} );
339376

377+
it( 'not update the position when is in not visible stack', () => {
378+
setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
379+
380+
linkUIFeature._showUI();
381+
382+
const customView = new View();
383+
384+
balloon.add( {
385+
stackId: 'custom',
386+
view: customView,
387+
position: { target: {} }
388+
} );
389+
390+
balloon.showStack( 'custom' );
391+
392+
expect( balloon.visibleView ).to.equal( customView );
393+
expect( balloon.hasView( actionsView ) ).to.equal( true );
394+
395+
const spy = testUtils.sinon.spy( balloon, 'updatePosition' );
396+
397+
editor.ui.fire( 'update' );
398+
399+
sinon.assert.notCalled( spy );
400+
} );
401+
340402
// https://github.com/ckeditor/ckeditor5-link/issues/113
341403
it( 'hides of the panel – editing a link, then the selection moved out of the link', () => {
342404
setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );

0 commit comments

Comments
 (0)