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

Commit

Permalink
Updating balloon position after DOM is rendered.
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonkups committed Feb 20, 2018
1 parent 592d38c commit dbc4cb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/link.js
Expand Up @@ -369,6 +369,7 @@ export default class Link extends Plugin {
let prevSelectedLink = this._getSelectedLinkElement();
let prevSelectionParent = getSelectionParent();

// Use 'low' priority to update position after view is rendered to the DOM.
this.listenTo( editingView, 'render', () => {
const selectedLink = this._getSelectedLinkElement();
const selectionParent = getSelectionParent();
Expand Down Expand Up @@ -399,7 +400,7 @@ export default class Link extends Plugin {

prevSelectedLink = selectedLink;
prevSelectionParent = selectionParent;
} );
}, { priority: 'low' } );

function getSelectionParent() {
return editingView.document.selection.focus.getAncestors()
Expand Down
18 changes: 17 additions & 1 deletion tests/link.js
Expand Up @@ -20,6 +20,7 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';

import Range from '@ckeditor/ckeditor5-engine/src/view/range';
import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';
import priorities from '@ckeditor/ckeditor5-utils/src/priorities';

testUtils.createSinonSandbox();

Expand Down Expand Up @@ -235,7 +236,7 @@ describe( 'Link', () => {
viewDocument = view.document;
} );

it( 'should not duplicate #change listeners', () => {
it( 'should not duplicate #render listeners', () => {
setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );

const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
Expand All @@ -249,6 +250,21 @@ describe( 'Link', () => {
sinon.assert.calledTwice( spy );
} );

it( 'should update position on #render with low priority', () => {
setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
linkFeature._showUI();

const spyBefore = sinon.spy();
const spy = sinon.spy( balloon, 'updatePosition' );
const spyAfter = sinon.spy();

view.on( 'render', spyBefore, { priority: priorities.get( 'low' ) + 1 } );
view.on( 'render', spyAfter, { priority: 'low' } );
view.fire( 'render' );

sinon.assert.callOrder( spyBefore, spy, spyAfter );
} );

// https://github.com/ckeditor/ckeditor5-link/issues/113
it( 'updates the position of the panel – editing a link, then the selection remains in the link', () => {
setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
Expand Down

0 comments on commit dbc4cb2

Please sign in to comment.