@@ -15,6 +15,8 @@ import RenameOperation from '../../src/model/operation/renameoperation';
1515import AttributeOperation from '../../src/model/operation/attributeoperation' ;
1616import { wrapInDelta } from '../../tests/model/_utils/utils' ;
1717
18+ import ViewContainerElement from '../../src/view/containerelement' ;
19+
1820describe ( 'ModelConversionDispatcher' , ( ) => {
1921 let dispatcher , doc , root , gyPos ;
2022
@@ -360,6 +362,78 @@ describe( 'ModelConversionDispatcher', () => {
360362 expect ( callArgs [ 1 ] ) . to . equal ( 'marker' ) ;
361363 expect ( callArgs [ 2 ] . isEqual ( markerRange ) ) . to . be . true ;
362364 } ) ;
365+
366+ it ( 'should not fire marker conversion if content is inserted into element with custom highlight handling' , ( ) => {
367+ sinon . spy ( dispatcher , 'convertMarker' ) ;
368+
369+ const text = new ModelText ( 'abc' ) ;
370+ const caption = new ModelElement ( 'caption' , null , text ) ;
371+ const image = new ModelElement ( 'image' , null , caption ) ;
372+ root . appendChildren ( [ image ] ) ;
373+
374+ // Create view elements that will be "mapped" to model elements.
375+ const viewCaption = new ViewContainerElement ( 'caption' ) ;
376+ const viewFigure = new ViewContainerElement ( 'figure' , null , viewCaption ) ;
377+
378+ // Create custom highlight handler mock.
379+ viewFigure . setCustomProperty ( 'addHighlight' , ( ) => { } ) ;
380+ viewFigure . setCustomProperty ( 'removeHighlight' , ( ) => { } ) ;
381+
382+ // Create mapper mock.
383+ dispatcher . conversionApi . mapper = {
384+ toViewElement ( modelElement ) {
385+ if ( modelElement == image ) {
386+ return viewFigure ;
387+ } else if ( modelElement == caption ) {
388+ return viewCaption ;
389+ }
390+ }
391+ } ;
392+
393+ const markerRange = ModelRange . createFromParentsAndOffsets ( root , 0 , root , 1 ) ;
394+ doc . markers . set ( 'marker' , markerRange ) ;
395+
396+ const insertionRange = ModelRange . createFromParentsAndOffsets ( caption , 1 , caption , 2 ) ;
397+ dispatcher . convertInsertion ( insertionRange ) ;
398+
399+ expect ( dispatcher . convertMarker . called ) . to . be . false ;
400+ } ) ;
401+
402+ it ( 'should fire marker conversion if inserted into element with highlight handling but element is not in marker range' , ( ) => {
403+ sinon . spy ( dispatcher , 'convertMarker' ) ;
404+
405+ const text = new ModelText ( 'abc' ) ;
406+ const caption = new ModelElement ( 'caption' , null , text ) ;
407+ const image = new ModelElement ( 'image' , null , caption ) ;
408+ root . appendChildren ( [ image ] ) ;
409+
410+ // Create view elements that will be "mapped" to model elements.
411+ const viewCaption = new ViewContainerElement ( 'caption' ) ;
412+ const viewFigure = new ViewContainerElement ( 'figure' , null , viewCaption ) ;
413+
414+ // Create custom highlight handler mock.
415+ viewFigure . setCustomProperty ( 'addHighlight' , ( ) => { } ) ;
416+ viewFigure . setCustomProperty ( 'removeHighlight' , ( ) => { } ) ;
417+
418+ // Create mapper mock.
419+ dispatcher . conversionApi . mapper = {
420+ toViewElement ( modelElement ) {
421+ if ( modelElement == image ) {
422+ return viewFigure ;
423+ } else if ( modelElement == caption ) {
424+ return viewCaption ;
425+ }
426+ }
427+ } ;
428+
429+ const markerRange = ModelRange . createFromParentsAndOffsets ( caption , 0 , caption , 3 ) ;
430+ doc . markers . set ( 'marker' , markerRange ) ;
431+
432+ const insertionRange = ModelRange . createFromParentsAndOffsets ( caption , 2 , caption , 3 ) ;
433+ dispatcher . convertInsertion ( insertionRange ) ;
434+
435+ expect ( dispatcher . convertMarker . called ) . to . be . true ;
436+ } ) ;
363437 } ) ;
364438
365439 describe ( 'convertMove' , ( ) => {
@@ -600,6 +674,46 @@ describe( 'ModelConversionDispatcher', () => {
600674 expect ( dispatcher . fire . calledWith ( 'selectionMarker:name' ) ) . to . be . true ;
601675 } ) ;
602676
677+ it ( 'should not fire event for marker if selection is in a element with custom highlight handling' , ( ) => {
678+ // Clear after `beforeEach`.
679+ root . removeChildren ( 0 , root . childCount ) ;
680+
681+ const text = new ModelText ( 'abc' ) ;
682+ const caption = new ModelElement ( 'caption' , null , text ) ;
683+ const image = new ModelElement ( 'image' , null , caption ) ;
684+ root . appendChildren ( [ image ] ) ;
685+
686+ // Create view elements that will be "mapped" to model elements.
687+ const viewCaption = new ViewContainerElement ( 'caption' ) ;
688+ const viewFigure = new ViewContainerElement ( 'figure' , null , viewCaption ) ;
689+
690+ // Create custom highlight handler mock.
691+ viewFigure . setCustomProperty ( 'addHighlight' , ( ) => { } ) ;
692+ viewFigure . setCustomProperty ( 'removeHighlight' , ( ) => { } ) ;
693+
694+ // Create mapper mock.
695+ dispatcher . conversionApi . mapper = {
696+ toViewElement ( modelElement ) {
697+ if ( modelElement == image ) {
698+ return viewFigure ;
699+ } else if ( modelElement == caption ) {
700+ return viewCaption ;
701+ }
702+ }
703+ } ;
704+
705+ doc . markers . set ( 'name' , ModelRange . createFromParentsAndOffsets ( root , 0 , root , 1 ) ) ;
706+ doc . selection . setRanges ( [ ModelRange . createFromParentsAndOffsets ( caption , 1 , caption , 1 ) ] ) ;
707+
708+ sinon . spy ( dispatcher , 'fire' ) ;
709+
710+ const markers = Array . from ( doc . markers . getMarkersAtPosition ( doc . selection . getFirstPosition ( ) ) ) ;
711+
712+ dispatcher . convertSelection ( doc . selection , markers ) ;
713+
714+ expect ( dispatcher . fire . calledWith ( 'selectionMarker:name' ) ) . to . be . false ;
715+ } ) ;
716+
603717 it ( 'should not fire events if information about marker has been consumed' , ( ) => {
604718 doc . markers . set ( 'foo' , ModelRange . createFromParentsAndOffsets ( root , 0 , root , 2 ) ) ;
605719 doc . markers . set ( 'bar' , ModelRange . createFromParentsAndOffsets ( root , 0 , root , 2 ) ) ;
0 commit comments