@@ -12,6 +12,7 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util
1212import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view' ;
1313
1414import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph' ;
15+ import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote' ;
1516import LinkEditing from '../src/linkediting' ;
1617import LinkUI from '../src/linkui' ;
1718import 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