@@ -14,7 +14,8 @@ import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
1414import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline' ;
1515import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph' ;
1616
17- import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js' ;
17+ import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model' ;
18+ import { stringify as viewStringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view' ;
1819
1920/* global document, setTimeout, window */
2021
@@ -199,6 +200,22 @@ describe( 'BalloonToolbar', () => {
199200 expect ( balloonAddSpy . firstCall . args [ 0 ] . position . target ( ) ) . to . deep . equal ( forwardSelectionRect ) ;
200201 } ) ;
201202
203+ // https://github.com/ckeditor/ckeditor5-ui/issues/385
204+ it ( 'should attach the #_balloon to the last range in a case of multi-range forward selection' , ( ) => {
205+ setData ( model , '<paragraph>b[ar]</paragraph><paragraph>[bi]z</paragraph>' ) ;
206+
207+ balloonToolbar . show ( ) ;
208+
209+ // Because attaching and pinning BalloonPanelView is stubbed for test
210+ // we need to manually call function that counting rect.
211+ const targetRect = balloonAddSpy . firstCall . args [ 0 ] . position . target ( ) ;
212+
213+ const targetViewRange = editingView . domConverter . viewRangeToDom . lastCall . args [ 0 ] ;
214+
215+ expect ( viewStringify ( targetViewRange . root , targetViewRange ) ) . to . equal ( '<div><p>bar</p><p>{bi}z</p></div>' ) ;
216+ expect ( targetRect ) . to . deep . equal ( forwardSelectionRect ) ;
217+ } ) ;
218+
202219 // https://github.com/ckeditor/ckeditor5-ui/issues/308
203220 it ( 'should ignore the zero-width orphan rect if there another one preceding it for the forward selection' , ( ) => {
204221 // Restore previous stubSelectionRects() call.
@@ -242,6 +259,22 @@ describe( 'BalloonToolbar', () => {
242259 expect ( balloonAddSpy . firstCall . args [ 0 ] . position . target ( ) ) . to . deep . equal ( backwardSelectionRect ) ;
243260 } ) ;
244261
262+ // https://github.com/ckeditor/ckeditor5-ui/issues/385
263+ it ( 'should attach the #_balloon to the first range in a case of multi-range backward selection' , ( ) => {
264+ setData ( model , '<paragraph>b[ar]</paragraph><paragraph>[bi]z</paragraph>' , { lastRangeBackward : true } ) ;
265+
266+ balloonToolbar . show ( ) ;
267+
268+ // Because attaching and pinning BalloonPanelView is stubbed for test
269+ // we need to manually call function that counting rect.
270+ const targetRect = balloonAddSpy . firstCall . args [ 0 ] . position . target ( ) ;
271+
272+ const targetViewRange = editingView . domConverter . viewRangeToDom . lastCall . args [ 0 ] ;
273+
274+ expect ( viewStringify ( targetViewRange . root , targetViewRange ) ) . to . equal ( '<div><p>b{ar}</p><p>biz</p></div>' ) ;
275+ expect ( targetRect ) . to . deep . equal ( backwardSelectionRect ) ;
276+ } ) ;
277+
245278 it ( 'should update balloon position on view#change event while balloon is added to the #_balloon' , ( ) => {
246279 setData ( model , '<paragraph>b[a]r</paragraph>' ) ;
247280
0 commit comments